题目传送门

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 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?

Input

Input contains multiple test cases. Each test case starts with two integers N and M (1 ≤ N ≤ 500, 0 ≤ M ≤ 2,000) in one line, which are the number of children and the number of rounds. Following are M lines, each line contains two integers in [0, N) separated by one symbol. The two integers are the IDs of the two children selected to play Rochambeau for this round. The symbol may be “=”, “>” or “<”, referring to a draw, that first child wins and that second child wins respectively.

Output

There is only one line for each test case. If the judge can be found, print the ID of the judge, and the least number of rounds after which the judge can be uniquely determined. If the judge can not be found, or the outcomes of the M rounds of game are inconsistent, print the corresponding message.

Sample Input

3 3
0<1
1<2
2<0
3 5
0<1
0>1
1<2
1>2
0<2
4 4
0<1
0>1
2<3
2>3
1 0

Sample Output

Can not determine

Player 1 can be determined to be the judge after 4 lines

Impossible

Player 0 can be determined to be the judge after 0 lines


  分析:比较复杂的一道扩展域并查集,不仅操作麻烦而且输入输出的要求还贼多。。。做的时候还遇到了一堆玄学错误。。。

  首先枚举每一个人,表示这个人是裁判,然后将没有这个人参与的比赛情况放入并查集中,如果没有矛盾则说名这个人可以是裁判,否则这个人就不能是裁判。如果发现没有满足要求的人,则输出Impossible,如果裁判不止一个则输出Can not determine,否则就可以输出这个人。在操作的时候可以放一个擂台记录一下line数。当然其中有很多小细节不好一一列举,具体看代码吧。

  Code:

//It is made by HolseLee on 29th May 2018
//POJ 2912
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
#define Fi(i,a,b) for(int i=a;i<=b;i++)
#define Fx(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=;const int M=;
int n,m,rank[N],fa[N];
inline int find(int a)
{
if(fa[a]!=a){
int father=find(fa[a]);
rank[a]=(rank[a]+rank[fa[a]])%;
fa[a]=father;}
return fa[a];
}
inline bool check(int a,int b,int c)
{
int fx=find(a);int fy=find(b);
if(fx==fy){if((rank[b]-rank[a]+)%!=c)return true;}
else{fa[fy]=fx;rank[fy]=(rank[a]-rank[b]+c+)%;}return false;
}
int main()
{
for(;scanf("%d%d",&n,&m)!=EOF;){
int x[M],y[M],ch[M];
int tot=,cnt=,ans=,c;bool flag;
Fi(i,,m){scanf("%d%c%d",&x[i],&ch[i],&y[i]);}
Fi(i,,n-){flag=true;Fi(j,,n-)fa[j]=j,rank[j]=;
Fi(j,,m){if(x[j]==i||y[j]==i)continue;
if(ch[j]=='=')c=;else if(ch[j]=='>')c=;else c=;
if(check(x[j],y[j],c)){cnt=max(cnt,j);flag=false;break;}}
if(flag){tot++;ans=i;}}
if(!tot)printf("Impossible\n");
else if(tot>)printf("Can not determine\n");
else printf("Player %d can be determined to be the judge after %d lines\n",ans,cnt);
}return ;
}

POJ2912 Rochambeau [扩展域并查集]的更多相关文章

  1. POJ2912 Rochambeau —— 种类并查集 + 枚举

    题目链接:http://poj.org/problem?id=2912 Rochambeau Time Limit: 5000MS   Memory Limit: 65536K Total Submi ...

  2. [POJ2912]Rochambeau(并查集)

    传送门 题意: n个人分成三组,玩石头剪子布游戏,同一组的人只能出同样固定的的手势,其中有一个是裁判不属于任何组,可以出任意手势,给出m个信息x op y 表示x,y是从三个组里面随机抽取的或者是裁判 ...

  3. NOI2001 食物链【扩展域并查集】*

    NOI2001 食物链 动物王国中有三类动物 A,B,C,这三类动物的食物链构成了有趣的环形.A 吃 B,B吃 C,C 吃 A. 现有 N 个动物,以 1 - N 编号.每个动物都是 A,B,C 中的 ...

  4. POJ1733 Parity game 【扩展域并查集】*

    POJ1733 Parity game Description Now and then you play the following game with your friend. Your frie ...

  5. POJ1733 Party game [带权并查集or扩展域并查集]

    题目传送 Parity game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10870   Accepted: 4182 ...

  6. P1525 关押罪犯[扩展域并查集]

    题目来源:洛谷 题目描述 S城现有两座监狱,一共关押着N名罪犯,编号分别为1−N.他们之间的关系自然也极不和谐.很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发冲突.我们用“怨气值”(一个正整 ...

  7. AcWing:240. 食物链(扩展域并查集 or 带边权并查集)

    动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形. A吃B, B吃C,C吃A. 现有N个动物,以1-N编号. 每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种. 有人用 ...

  8. AcWing:239. 奇偶游戏(前缀和 + 离散化 + 带权并查集 + 异或性质 or 扩展域并查集 + 离散化)

    小A和小B在玩一个游戏. 首先,小A写了一个由0和1组成的序列S,长度为N. 然后,小B向小A提出了M个问题. 在每个问题中,小B指定两个数 l 和 r,小A回答 S[l~r] 中有奇数个1还是偶数个 ...

  9. poj2912 带权并查集

    题意:多个人玩石头剪刀布,每个人提前选定了自己出哪个手势,而其中有一种特殊的人他可以随意出什么手势,问是否能够从给出的一系列石头剪刀布游戏中判断出哪个是特殊的,可以从第几局游戏中判断出来. 首先按照食 ...

随机推荐

  1. linux部署j2eeweb工程涉及到的指令

    1.查看java进程: ps -e | grep java; 可以获取到java进程的进程号. 或: ps -ef | grep java; 可以查看到详细的进程信息 2.杀死java进程 kill ...

  2. DBA操作常用命令

    一.ORACLE的启动和关闭   1.在单机环境下   要想启动或关闭ORACLE系统必须首先切换到ORACLE用户,如下   su - oracle      a.启动ORACLE系统   orac ...

  3. jquery 条形码 插件jquery-barcode使用

    转载文章   jquery 条形码 插件jquery-barcode使用 条码官网: http://barcode-coder.com/en/barcode-jquery-plugin-201.htm ...

  4. html 让一行文字居中

    文本在行高范围内垂直居中 可以利用行高特性让一行文本居中 line-height:100px://父容器的高度

  5. 【51NOD-0】1046 A^B Mod C

    [算法]快速幂运算 [题解]快速幂的原理是把幂用二进制表示,从最低位a,次低位a2,次次低位(a2)2. #include<cstdio> long long quick_pow(long ...

  6. node启动服务

    npm install http-server -g http-server ipconfig查看当前ip 手机可访问第一个网址.

  7. 自动化测试===Macaca环境搭建,自我总结

    安装jdk 安装安卓sdk(打开sdk的时候出现问题linux===启动sdk manager下载配置sdk的时候报错的解决办法) 安装gradle,配置环境变量(MACACA===gradle下载和 ...

  8. 0x3F3F3F3F——ACM中的无穷大常量

    在算法竞赛中,我们常常需要用到设置一个常量用来代表“无穷大”. 比如对于int类型的数,有的人会采用INT_MAX,即0x7fffffff作为无穷大.但是以INT_MAX为无穷大常常面临一个问题,即加 ...

  9. 2017多校第9场 HDU 6166 Senior Pan 堆优化Dij

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6166 题意:给你一个有向图,然后给你k个点,求其中一个点到另一个点的距离的最小值. 解法:枚举二进制位 ...

  10. FineReport——JS二次开发(复选框全选)

    在进行查询结果选择的时候,我们经常会用到复选框控件,对于如何实现复选框全选,基本思路: 在复选框中的初始化事件中把控件加入到一个全局数组里,然后在全选复选框里对数组里的控件进行遍历赋值. 首先,定义两 ...