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 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 题目大意:小朋友们玩石头剪刀布,决定了出什么之后就会一直出什么。除了裁判,裁判每次出的招式可能不一样。给出几组比试结果,求出谁是裁判。如果能求出则写出最少在几组比试结果之后就能得出结果。如果求不出,则给出不可能求得出或者是结果可能性太多无法判定。
思路:并查集食物链的加强版。在求出父亲的同时,还增加了一个关系说明。a[x]表示x与其父亲fx的关系。1:fx<x。2:fx>x。3:fx=x。
每次求出父亲的时候还要计算他们之间的关系。
求裁判时,枚举谁是裁判。然后将裁判的出拳结果出数据中去掉,接下来开始求小朋友间的胜负关系是否矛盾。如果出了去除裁判k之外,去除其他都会得出矛盾,则裁判是k。如果去除多个数都没有矛盾,裁判无法判断。如果去除谁有矛盾,则不可能求出结果。
/*
* Author: Joshua
* Created Time: 2014年07月12日 星期六 10时47分42秒
* File Name: poj2912.cpp
*/
#include<cstdio>
#include<algorithm>
#include<cstring>
#define maxn 505
#define maxm 2005 using namespace std;
typedef long long LL;
int n,m;
int a[maxn],f[maxn]; int gf(int x)
{
if (f[x]!=x)
{
int fx=f[x];
f[x]=gf(f[x]);
a[x]=(a[x]+a[fx])%;
}
return f[x];
} void solve()
{
int x[maxm],y[maxm],p[maxm];
int ans,err,step=,gfx,gfy,type,xx,yy,cnt=;
char c;
for (int i=;i<=m;++i)
{
scanf("%d%c%d",&x[i],&c,&y[i]);
if (c=='<') p[i]=;
if (c=='>') p[i]=;
if (c=='=') p[i]=;
}
for (int i=;i<n;++i)
{
for (int j=;j<n;++j)
{
a[j]=;
f[j]=j;
}
err=;
for (int j=;j<=m && !err;++j)
{
xx=x[j];
yy=y[j];
if (xx==i || yy==i) continue;
gfx=gf(xx);
gfy=gf(yy);
type=(a[xx]-a[yy]+p[j]+)%;
if (gfy!=gfx)
{
f[gfy]=gfx;
a[gfy]=type;
}
else if ((a[xx]+p[j])%!=a[yy])
err=j;
}
if (err)
{
cnt++;
step=max(step,err);
}
else
ans=i;
}
if (cnt==n) printf("Impossible\n");
else if (cnt<n-) printf("Can not determine\n");
else printf("Player %d can be determined to be the judge after %d lines\n",ans,step);
}
int main()
{
while (scanf("%d%d",&n,&m)==)
{
solve();
}
return ;
}
poj2912 Rochambeau的更多相关文章
- POJ2912 Rochambeau [扩展域并查集]
题目传送门 Rochambeau Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 4463 Accepted: 1545 ...
- POJ2912:Rochambeau(带权并查集)
Rochambeau Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5208 Accepted: 1778 题目链接:h ...
- POJ2912 Rochambeau —— 种类并查集 + 枚举
题目链接:http://poj.org/problem?id=2912 Rochambeau Time Limit: 5000MS Memory Limit: 65536K Total Submi ...
- [POJ2912]Rochambeau(并查集)
传送门 题意: n个人分成三组,玩石头剪子布游戏,同一组的人只能出同样固定的的手势,其中有一个是裁判不属于任何组,可以出任意手势,给出m个信息x op y 表示x,y是从三个组里面随机抽取的或者是裁判 ...
- 【转】并查集&MST题集
转自:http://blog.csdn.net/shahdza/article/details/7779230 [HDU]1213 How Many Tables 基础并查集★1272 小希的迷宫 基 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- hdu图论题目分类
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- HDU图论题单
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- 【POJ2912】【并查集】Rochambeau
Description N children are playing Rochambeau (scissors-rock-cloth) game with you. One of them is th ...
随机推荐
- FTP publisher plugin插件
说明:这个插件可以将构建的产物(例如:Jar)发布到FTP中去. 官方说明:FTP publisher plugin 安装步骤: 系统管理→管理插件→可选插件→Artifact Uploaders→F ...
- (转)Sublime Text2 快捷键汇总
场景:最近在编写项目中越发的感觉到一个得心应手的编辑器是多么的重要,而sublime,无疑是让我用着最舒服,最有感觉的编辑器了! 1 快捷键总结 一个好的编辑器,能大大提高编程的效率.如果能熟知软件的 ...
- (转)maven镜像路径配置
很多maven包无法自动下载怎么办?设置maven镜像setting.xml <mirror> <id>repo2</id> <mirrorOf>cen ...
- CSS随笔1(CSS常用样式)
样式 属性 大小 font-size(x-large ; xx-small ; 可用数值单位 : PX,PD) 样式 font-style(oblique 偏斜体 : italic 斜体 : norm ...
- matrix()方法与translate()、scale()、rotate()、skew()方法的关系
2D变换方法translate().scale().rotate().skew()与matrix()的关系举例介绍. 一.介绍 2D变换方法: translate():根据左(X轴)和顶部(Y轴)位置 ...
- zookeeper单机模式安装
zookeeper单机模式安装 更多文章:http://blogxinxiucan.sh1.newtouch.com/2017/07/26/zookeeper单机模式安装/ 下载zookeeper u ...
- 华为服务器Linux在线做RAID方法
背景概述 最近维护大数据的一些主机,大概有3k+的数目,有很大一部分是华为的服务器,大部分是12块数据盘,单盘做RAID0来存放数据,但是通常硬件是不可靠的,磁盘损坏是常态, 然而磁盘损坏进行定位更换 ...
- Git在tortoiseGit以及eclipse的使用方法
一.Git安装与简单使用 1.安装git,tortoiseGit 2.创建SSH Key 打开Git Bash,然后输入ssh-keygen生成公钥和私钥: 3.生成ppk文件. 打开puttykey ...
- RSA加密解密及RSA加签验签
RSA安全性应用场景说明 在刚接触RSA的时候,会混淆RSA加密解密和RSA加签验签的概念.简单来说加密解密是公钥加密私钥解密,持有公钥(多人持有)可以对数据加密,但是只有持有私钥(一人持有)才可以解 ...
- 到底什么样的企业才适合实施SAP系统?
SAP系统作为全宇宙第一的ERP,号称世界500强里面有80%的企业部署了SAP系统,总部位于德国沃尔多夫市,在全球拥有6万多名员工,遍布全球130个国家,并拥有覆盖全球11,500家企业的合作伙伴网 ...