题目传送门

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

最新文章

  1. Nodemanager Out of heap memory[fix bug全过程]
  2. JavaScript Modules
  3. Javascript函数(定义、传值、重载)
  4. [改善Java代码]用偶判断,不用奇判断
  5. Log4net日志组件使用
  6. StringTokenizer使用类
  7. python调用ansible api 2.0 运行playbook带callback返回
  8. 2017最新xcode打包APP详细图文
  9. c# 第一节课 一些简单的应用
  10. 【ThinkPHP框架学习 】(2) --- 后台管理系统如何用iframe点击左边右边局部刷新
  11. zend Framework的MVC模式的搭建
  12. bzoj 2209 [Jsoi2011]括号序列 平衡树
  13. Codeforces 833D Red-Black Cobweb [点分治]
  14. 【python】内存调试
  15. GraphQL: Object doesn&#39;t support property or method &#39;from&#39;
  16. jquery Jquery 遍历 获取设置 效果
  17. 关于Entity Framework更新的几种方式以及可能遇到的问题(附加类型“Model”的实体失败,因为相同类型的其他实体已具有相同的主键值)在使用 &quot;Attach&quot; 方法或者将实体的状态设置为 &quot;Unchanged&quot; 或 &quot;Modified&quot; 时如果图形中的任何实体具有冲突键值,则可能会发生上述行为
  18. 【VSC】.txt文件打开乱码
  19. shell 将输入的字符转换成大写
  20. 微信小程序开发6-WXSS

热门文章

  1. HNOI 2016 地图
  2. iOS tag的使用
  3. (转)Linux下使Shell 命令脱离终端在后台运行
  4. Winform GDI+
  5. js 的function为什么可以添加属性
  6. charles &amp; Fiddle
  7. python碎片记录(一)
  8. 史诗级Java/JavaWeb学习资源免费分享
  9. net_device-&gt;uc_promisc
  10. CiteSeer统计的计算机领域的期刊和会议的影响因子(2005)