码迷,mamicode.com
首页 > 其他好文 > 详细

POJ2912 Rochambeau (hard?or!hard?)

时间:2014-11-05 16:21:24      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:des   io   ar   os   for   sp   div   on   art   

Description

N children are playing Rochambeau (scissors-rock-cloth) game with you. One of them is the judge. The rest children are divided into three groups (it is possible that some group is empty). You don’t know who is the judge, or how the children are grouped. Then the children start playing Rochambeau game for M rounds. Each round two children are arbitrarily selected to play Rochambeau for one once, and you will be told the outcome while not knowing which gesture the children presented. It is known that the children in the same group would present the same gesture (hence, two children in the same group always get draw when playing) and different groups for different gestures. The judge would present gesture randomly each time, hence no one knows what gesture the judge would present. Can you guess who is the judge after after the game ends? If you can, after how many rounds can you find out the judge at the earliest? 


题目大意:(剪子包袱锤~~)不过,多了个美丽的judge,可以随便出任何种手势。判断能否根据已知的游戏的结果选出judge。。。

思路:基本用食物链。。。不过。。。多了个美丽的judge,就困难了些。。。提高到了baidustart的难度(06年~~)。
 枚举每个小孩为judge,判断他为judge时在第几句话出错falt[i](即到第几句话能判断该小孩不是judge)。
1. 如果只有1个小孩是judge时全部语句都是正确的,说明该小孩是judge,那么判断的句子数即为其他小孩的falt[i]的最大值。如果
2. 如果每个小孩的都不是judge(即都可以找到出错的语句),那么就是impossible。
3. 多于1个小孩是judge时没有找到出错的语句,就是Can not determine。
小小的借鉴了一下题解。。。被组里的人骂了,crying。。。
 
细节来说:小孩是从0开始编号的。
 
code:
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
struct use{
int a1,a2,kind;
}a[2001];
int fa[1501]={0},b[501]={0};
char ch[100];
int rool(int x)
{
if (fa[x]!=x) fa[x]=rool(fa[x]);
return fa[x];
}
int main()
{
int i,j,r1,r2,n,m,ci,ans,l,ansn,judge,aa,bb,maxn;
bool f;
while (scanf("%d%d",&n,&m)==2)
{
if (m==0)
printf("Player 0 can be determined to be the judge after 0 lines\n");
else
{
ans=0;
memset(b,0,sizeof(b));
memset(a,0,sizeof(a));
for (i=1;i<=3*n;++i)
 fa[i]=i;
for (i=1;i<=m;++i)
{
scanf("%s",&ch);
l=strlen(ch);
j=0;
while (ch[j]>=‘0‘&&ch[j]<=‘9‘)
{
a[i].a1=a[i].a1*10+ch[j]-‘0‘;
++j;
}
   ++a[i].a1;
if (ch[j]==‘=‘) a[i].kind=0;
if (ch[j]==‘>‘) a[i].kind=1;
if (ch[j]==‘<‘) a[i].kind=-1;
++j;
while (ch[j]>=‘0‘&&ch[j]<=‘9‘&&j<l)
{
a[i].a2=a[i].a2*10+ch[j]-‘0‘;
++j;
}
++a[i].a2;
}
   for (judge=1;judge<=n;++judge)
   {
   f=false;
   for (i=1;i<=3*n;++i)
       fa[i]=i;
   for (i=1;i<=m;++i)
   {
   if (a[i].a1==judge||a[i].a2==judge) continue;
   if (a[i].kind==0)
   {
   aa=a[i].a1;
   bb=a[i].a2;
   if (rool(aa+n)==rool(bb)||rool(aa+2*n)==rool(bb))
   {
   b[judge]=i;
   f=true;
   break;
   }
   r1=rool(aa);
   r2=rool(bb);
   if (r1!=r2)
   {
   fa[r1]=r2;
   fa[rool(aa+n)]=rool(bb+n);
   fa[rool(aa+2*n)]=rool(bb+2*n);
   }
   }
   else
   {
   if (a[i].kind==1)
   {
   aa=a[i].a1;
   bb=a[i].a2;
   }
   else
   {
   aa=a[i].a2;
   bb=a[i].a1;
   }
   if (rool(aa)==rool(bb)||rool(aa+2*n)==rool(bb))
   {
   b[judge]=i;
   f=true;
   break;
   }
   fa[rool(aa+n)]=rool(bb);
   fa[rool(aa+2*n)]=rool(bb+n);
   fa[rool(aa)]=rool(bb+2*n);
       }
   }
   if (!f) 
   {
   ++ans;
   ansn=judge;
   }
   }
   if (ans>1) printf("Can not determine\n");
   if (ans==0) printf("Impossible\n");
   if (ans==1)
   {
   maxn=0;
   for (i=1;i<=n;++i)
     if (b[i]>maxn) maxn=b[i];
   printf("Player %d can be determined to be the judge after %d lines\n",ansn-1,maxn);
   }
        }
}

 

POJ2912 Rochambeau (hard?or!hard?)

标签:des   io   ar   os   for   sp   div   on   art   

原文地址:http://www.cnblogs.com/Rivendell/p/4076351.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!