POJ2912 Rochambeau (hard?or!hard?)

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);

}

}

}

}

时间: 2024-10-13 10:20:44

POJ2912 Rochambeau (hard?or!hard?)的相关文章

poj2912 Rochambeau

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 childr

POJ2912 Rochambeau [扩展域并查集]

题目传送门 Rochambeau Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4463   Accepted: 1545 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

并查集练习2(带权并查集)

明天旅游去爬山逛庙玩,今天练一天然后早早睡觉啦~ poj1703 Find them, Catch them (带权并查集) 1 #include<cstdio> 2 const int N=1e5+1; 3 int f[N]; 4 int r[N];//表示与父节点的关系,0同类,1不同类 5 int n; 6 void init(){ 7 for(int i=1;i<=n;++i){ 8 f[i]=i; r[i]=0; 9 } 10 } 11 int fin(int x){ 12 i

题单二:图论500

http://wenku.baidu.com/link?url=gETLFsWcgddEDRZ334EJOS7qCTab94qw5cor8Es0LINVaGMSgc9nIV-utRIDh--2UwRLvsvJ5tXFjbdpzbjygEdpGehim1i5BfzYgYWxJmu ==========  以下是最小生成树+并查集=========================[HDU]1213         How Many Tables        基础并查集★1272         小

图论五百题!

生死看淡不服就淦,这才是人生! =============================以下是最小生成树+并查集======================================[HDU]1213 How Many Tables 基础并查集★1272 小希的迷宫 基础并查集★1325&&poj1308 Is It A Tree? 基础并查集★1856 More is better 基础并查集★1102 Constructing Roads 基础最小生成树★1232 畅通工程 基

图论 500题——主要为hdu/poj/zoj

转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并查集======================================[HDU]1213   How Many Tables   基础并查集★1272   小希的迷宫   基础并查集★1325&&poj1308  Is It A Tree?   基础并查集★1856   More i

并查集&amp;MST

[HDU] 1198 Farm Irrigation 基础最小生成树★ 1598 find the most comfortable road 枚举+最小生成树★★ 1811 Rank of Tetris 并查集+拓扑排序★★ 3926 Hand in Hand 同构图★ 3938 Portal 离线+并查集★★ 2489     Minimal Ratio Tree dfs枚举组合情况+最小生成树★ 4081     Qin Shi Huang's National Road System 最

图论精炼500题

忘了从哪转的了... =============================以下是最小生成树+并查集====================================== [HDU] 1213               How Many Tables                    基础并查集★ 1272               小希的迷宫                     基础并查集★ 1325&&poj1308    Is It A Tree?       

hdu图论题目分类

=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many Tables 基础并查集★ 1272 小希的迷宫 基础并查集★ 1325&&poj1308 Is It A Tree? 基础并查集★ 1856 More is better 基础并查集★ 1102 Constructing Roads 基础最小生成树★ 1232 畅通工程 基础并查集★ 123