【35.53%】【POJ 2912】Rochambeau
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 2837 Accepted: 1008
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
Source
Baidu Star 2006 Preliminary
Chen, Shixi (xreborner) living in http://fairyair.yeah.net/
【题解】
做法:
带权并查集
枚举某个人是裁判。如果它是裁判仍会发生冲突。那么就记录最先发生冲突的点在哪里;
(遇到和裁判有关的信息就直接跳过。因为裁判可以什么都出,所以它的信息没有意义。);
记录有多少个人满足:如果裁判是这个人整段信息不会发生冲突;
设为cnt;
如果cnt为0则说明不管谁是裁判都会发生冲突。则所给的信息是impossible的;
如果cnt为1则说明恰好有一个人满足裁判的要求。那么裁判就是他了。至于最早判断的地方就是其他n-1个不满足要求的裁判最早发生冲突的点的最大值。只有在那个信息结束后才能判断其他人不是裁判。
如果cnt大于1,则有多个人满足要求。那么就不能确定。
带权并查集的状态转移和食物链那题类似,我发下链接:
http://blog.csdn.net/harlow_cheng/article/details/52736452
#include <cstdio>
#include <algorithm>
const int MAXN = 600;
const int MAXM = 2999;
struct rec
{
int x, y, z;
};
int n, m;
int f[MAXN], re[MAXN],fe[MAXN];
rec a[MAXM];
//0 same
//1 shu
//2 ying
int ff(int x)
{
if (f[x] == x)
return x;
int olfa = f[x];
f[x] = ff(f[x]);
re[x] = (re[x] + re[olfa]) % 3;
return f[x];
}
int main()
{
//freopen("F:\\rush.txt", "r", stdin);
while (~scanf("%d%d", &n, &m))
{
for (int i = 1; i <= m; i++)
{
char t;
scanf("%d", &a[i].x);
t = getchar();
while (t == ' ') t = getchar();
scanf("%d", &a[i].y);
if (t == '<')
a[i].z = 1;
else
if (t == '>')
a[i].z = 2;
else
a[i].z = 0;
}
for (int i = 0; i <= n - 1; i++)
fe[i] = -1;
for (int ju = 0; ju <= n - 1; ju++)
{
for (int i = 0; i <= n - 1; i++)
f[i] = i, re[i] = 0;
for (int i = 1; i <= m; i++)
{
if (a[i].x == ju || a[i].y == ju)
continue;
int l = ff(a[i].x), r = ff(a[i].y);
if (l == r)
{
int temp = (re[a[i].x] - re[a[i].y] + 3) % 3;
if (temp != a[i].z)
{
fe[ju] = i;
break;
}
}
else
{
f[l] = r;
re[l] = (a[i].z + re[a[i].y] - re[a[i].x] + 3) % 3;
}
}
}
int cnt = 0,judge,ma = 0;
for (int i = 0; i <= n - 1; i++)
{
if (fe[i] == -1)
{
cnt++;
judge = i;
}
ma = std::max(ma, fe[i]);
}
if (cnt == 0)
puts("Impossible");
else
if (cnt == 1)
printf("Player %d can be determined to be the judge after %d lines\n", judge, ma);
else
printf("Can not determine\n");
}
return 0;
}
【35.53%】【POJ 2912】Rochambeau的更多相关文章
- 【poj 1984】&【bzoj 3362】Navigation Nightmare(图论--带权并查集)
题意:平面上给出N个点,知道M个关于点X在点Y的正东/西/南/北方向的距离.问在刚给出一定关系之后其中2点的曼哈顿距离((x1,y1)与(x2,y2):l x1-x2 l+l y1-y2 l),未知则 ...
- 【BZOJ 2288】 2288: 【POJ Challenge】生日礼物 (贪心+优先队列+双向链表)
2288: [POJ Challenge]生日礼物 Description ftiasch 18岁生日的时候,lqp18_31给她看了一个神奇的序列 A1, A2, ..., AN. 她被允许选择不超 ...
- 【poj 3090】Visible Lattice Points(数论--欧拉函数 找规律求前缀和)
题意:问从(0,0)到(x,y)(0≤x, y≤N)的线段没有与其他整数点相交的点数. 解法:只有 gcd(x,y)=1 时才满足条件,问 N 以前所有的合法点的和,就发现和上一题-- [poj 24 ...
- 【poj 1988】Cube Stacking(图论--带权并查集)
题意:有N个方块,M个操作{"C x":查询方块x上的方块数:"M x y":移动方块x所在的整个方块堆到方块y所在的整个方块堆之上}.输出相应的答案. 解法: ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【POJ】【2348】Euclid‘s Game
博弈论 题解:http://blog.sina.com.cn/s/blog_7cb4384d0100qs7f.html 感觉本题关键是要想到[当a-b>b时先手必胜],后面的就只跟奇偶性有关了 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
随机推荐
- sublime配置node开发环境
下载node插件 https://github.com/tanepiper/SublimeText-Nodejs 下载zip压缩包后解压,文件名改为Node 打开文件“Nodejs.sublime-s ...
- PHPCMS快速建站系列之标签循环嵌套
标签循环嵌套方法,可以实现对PC标签循环调用,代码如下: 在此文件里/phpcms/lib/classes/template_cache.class.php 里的 template_parse 方法里 ...
- KiCad EDA 画圆弧
KiCad EDA 画圆弧 看起来像是成功了. KiCad 画圆弧一直没有完善解决,但是 KiCad 一直有在努力.
- HZOJ 巨神兵
60pts: 每个DAG的拓扑序是唯一的,所以考虑将DAG分层.f[i][j]记录当前选择的节点状态是i,最后一层的节点状态为j(dep取最大). 初始状态:$f[i][i]=1;i\in [1,1& ...
- CAD专用卸载修复工具,一键完全彻底卸载删除CAD软件的专用卸载工具
Autodesk CAD卸载工具(AUTO Uninstaller)是专门为了针对Autodesk CAD软件卸载不干净而导致CAD安装失败问题进行研发的Autodesk CAD一键卸载工具.现在虽然 ...
- TreeSet的运用之使用内部比较器实现自定义有序(重要)
Student.java package com.sxt.set3; /* * TreeSet:有序 * implements Comparable<Student> * 如果用内部比较器 ...
- 轻松学习之 IMP指针的作用
http://www.cocoachina.com/ios/20150717/12623.html 可能大家一直看到有许多朋友在Runtime相关文章中介绍IMP指针的概念,那么IMP究竟有什么实际作 ...
- Java练习 SDUT-1253_进制转换
进制转换 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 输入一个十进制数N,将它转换成R进制数输出. Input 输入 ...
- Redis源码解析:09redis数据库实现(键值对操作、键超时功能、键空间通知)
本章对Redis服务器的数据库实现进行介绍,说明Redis数据库相关操作的实现,包括数据库中键值对的添加.删除.查看.更新等操作的实现:客户端切换数据库的实现:键超时相关功能的实现.键空间事件通知等. ...
- @总结 - 2@ 位运算卷积/子集卷积 —— FWT/FMT
目录 @0 - 参考资料@ @1 - 异或卷积概念及性质@ @2 - 快速沃尔什正变换(异或)@ @3 - 快速沃尔什逆变换(异或)@ @4 - 与卷积.或卷积@ @5 - 参考代码实现@ @6 - ...