题目链接:http://poj.org/problem?id=2912 

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1751

题意:有n个人玩石头剪刀布,所以会产生石头>剪刀,剪刀>布,布>石头,所以就产生了和食物链那题一样的关系;

枚举+关系并查集,枚举每个小孩为judge时的情况,若当前枚举情况下每个round都是正确的,则当前枚举编号可能是judge。

若只找到一个judge的可能,即为输出。若有多个就不确定了;

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <vector>
using namespace std;
typedef long long LL;
#define N 2520
#define met(a, b) memset(a, b, sizeof(a)) int f[N], r[N], wrong[N]; int Find(int x)
{
int k = f[x];
if(x!=f[x])
{
f[x] = Find(f[x]);
r[x] = (r[x]+r[k])%;
}
return f[x];
} struct node
{
int x, y, op;
}a[N];
int main()
{
int n, m;
while(scanf("%d %d", &n, &m)!=EOF)
{
met(a, ); for(int i=; i<=m; i++)
{
char ch;
scanf("%d%c%d", &a[i].x, &ch, &a[i].y);
if(ch == '=') a[i].op = ;
if(ch == '>') a[i].op = ;
if(ch == '<') a[i].op = ;
} for(int i=; i<n; i++)///枚举裁判;
{
for(int j=; j<n; j++)
f[j] = j, r[j] = ; wrong[i] = ;///第i个人当裁判的时候在哪产生矛盾;
for(int j=; j<=m; j++)
{
if(a[j].x == i || a[j].y == i)continue;
int x = a[j].x, y = a[j].y; int px = Find(x);
int py = Find(y); if(px != py)
{
f[px] = py;
r[px] = (r[y] + a[j].op - r[x] + )%;
}
else if(px == py && (r[y]+a[j].op)% != r[x])
{
wrong[i] = j;
break;
}
}
}
int judge = , ans = , Index;
for(int i=; i<n; i++)
{
if(wrong[i] == )
{
judge++;
Index = i;
}
ans = max(wrong[i], ans);///当其他的情况矛盾了,那么就是确定结果的时候;
}
if(judge == ) printf("Player %d can be determined to be the judge after %d lines\n", Index, ans);
else if(judge == ) printf("Impossible\n");///没有产生;
else printf("Can not determine\n");///产生的不止一个,就是不确定;
}
return ;
}

Rochambeau---poj2912||zoj2751(并查集类似于食物链)的更多相关文章

  1. poj 1182:食物链(种类并查集,食物链问题)

    食物链 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44168   Accepted: 12878 Description ...

  2. poj 2912 并查集(食物链加强版)

    题目:给出n个人玩剪刀石头布的游戏,其中有一个人是裁判,剩下的人分为3组,每一组的人只出某一种手型,裁判可以任意出.问是否能判断出哪个人是裁判 链接:点我 分分钟看吐血,先把食物链看懂吧 枚举裁判,然 ...

  3. POJ2912:Rochambeau(带权并查集)

    Rochambeau Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5208   Accepted: 1778 题目链接:h ...

  4. POJ - 2912 Rochambeau (带权并查集+枚举)

    题意:有N个人被分为了三组,其中有一个人是开了挂的.同组的人的关系是‘=’,不同组的人关系是‘<’或'>',但是开了挂的人可以给出自己和他人任意的关系.现在要根据M条关系找出这个开了挂的人 ...

  5. poj2912(种类并查集+枚举)

    题目:http://poj.org/problem?id=2912 题意:n个人进行m轮剪刀石头布游戏(0<n<=500,0<=m<=2000),接下来m行形如x, y, ch ...

  6. POJ 2912 Rochambeau(种类并查集+枚举)

    题目链接:http://poj.org/problem?id=2912 题目大意:n个人玩,玩石头剪刀布游戏,其中1人是裁判,剩下的n-1个人分为3组, 他们商量好了,相同组的人每次都出相同的手势,不 ...

  7. 并查集-G - 食物链

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

  8. 分类并查集[noi2001 食物链]

    题目链接:http://cogs.pro:8081/cogs/problem/problem.php?pid=pxNJzxVPU 题目有三种动物,A吃B,B吃C,C吃A 即B是A的食物,A是B的天敌, ...

  9. POJ1703Find them, Catch them[种类并查集]

    Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42416   Accepted: ...

随机推荐

  1. How do I commit all deleted files in Git?

    Try this: $ git add -u This tells git to automatically stage tracked files -- including deleting the ...

  2. 超全面的JavaWeb笔记day10<Response&Request&路径&编码>

    1.Response 2.Request 3.路径 4.编码 请求响应流程图 response 1.response概述 response是Servlet.service方法的一个参数,类型为java ...

  3. Java精选笔记_IO流【File(文件)类、遍历目录下的文件、删除文件及目录】

    File(文件)类 File类用于封装一个路径,该路径可以是从系统盘符开始的绝对路径,也可以是相对于当前目录而言的相对路径 File类内部封装的路径可以指向一个文件,也可以指向一个目录,在使用File ...

  4. Python 中文乱码

    1.首行添加 # -*- coding:gb2312 -*- # -*- coding:utf-8 -*- 2.PyCharm设置 在File->setting->File Encodin ...

  5. python远程登录服务器(paramiko模块安装和使用)

    转自:http://www.jb51.net/article/46285.htm 一:简介 由paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器 ...

  6. IOS视频播放器的制作

    利用自带MPMoviePlayerController来实现视频播放,首先要在项目中导入MediaPlayer.Framework框架包. 在视图控制器中 #import "MediaPla ...

  7. Spring学习笔记--构造器注入

    之前讲到的名为"duke"的bean有一个私有成员变量beanBags代表这个杂技师bean的一次性能够抛出的最多的数量,Juggler有一个构造函数,构造函数的第一个参数(这里只 ...

  8. 在centos命令行下安装软件

    考虑到用linux纯命令行模式时,通常都是用作服务器,所以,一般主要是安装一个php.mysql.apache的集成环境和ftp服务器,在这里用xampp集成包即可解决所有问题,在这里说一下我自己的做 ...

  9. ubuntu 安装nfs 服务

    1. 安装nfs服务软件 (1)服务器端 $sudo apt-get install nfs-kernel-server  rpcbind (2)客户端 (可以省略) $sudo apt-get in ...

  10. Dockerfile分享之SSH Server

    版权声明:本文由姚俊刚原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/84 来源:腾云阁 https://www.qclou ...