Rochambeau---poj2912||zoj2751(并查集类似于食物链)
题目链接: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(并查集类似于食物链)的更多相关文章
- poj 1182:食物链(种类并查集,食物链问题)
食物链 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44168 Accepted: 12878 Description ...
- poj 2912 并查集(食物链加强版)
题目:给出n个人玩剪刀石头布的游戏,其中有一个人是裁判,剩下的人分为3组,每一组的人只出某一种手型,裁判可以任意出.问是否能判断出哪个人是裁判 链接:点我 分分钟看吐血,先把食物链看懂吧 枚举裁判,然 ...
- POJ2912:Rochambeau(带权并查集)
Rochambeau Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5208 Accepted: 1778 题目链接:h ...
- POJ - 2912 Rochambeau (带权并查集+枚举)
题意:有N个人被分为了三组,其中有一个人是开了挂的.同组的人的关系是‘=’,不同组的人关系是‘<’或'>',但是开了挂的人可以给出自己和他人任意的关系.现在要根据M条关系找出这个开了挂的人 ...
- poj2912(种类并查集+枚举)
题目:http://poj.org/problem?id=2912 题意:n个人进行m轮剪刀石头布游戏(0<n<=500,0<=m<=2000),接下来m行形如x, y, ch ...
- POJ 2912 Rochambeau(种类并查集+枚举)
题目链接:http://poj.org/problem?id=2912 题目大意:n个人玩,玩石头剪刀布游戏,其中1人是裁判,剩下的n-1个人分为3组, 他们商量好了,相同组的人每次都出相同的手势,不 ...
- 并查集-G - 食物链
G - 食物链 动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形.A吃B, B吃C,C吃A.现有N个动物,以1-N编号.每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种 ...
- 分类并查集[noi2001 食物链]
题目链接:http://cogs.pro:8081/cogs/problem/problem.php?pid=pxNJzxVPU 题目有三种动物,A吃B,B吃C,C吃A 即B是A的食物,A是B的天敌, ...
- POJ1703Find them, Catch them[种类并查集]
Find them, Catch them Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42416 Accepted: ...
随机推荐
- 【Java面试题】6 判断下面代码是否有问题
1. if(username.equals(“zxx”){} 2. int x = 1; return x==1?true:false; 1.一个变量直接调用equals方法会给程序带来安全隐患,直接 ...
- [LeetCode] Subsets II [32]
题目 Given a collection of integers that might contain duplicates, S, return all possible subsets. Not ...
- 动态提交使用jQuery 完成ajax 文件下载----后端php
1.js代码 // Ajax 文件下载 //当不用传参时,可以将data去掉 jQuery.download = function(url, data, method){ // 获得url和data ...
- java程序后台报错java.net.SocketException: Too many open files
问题描述: 今天一个同事反映程序有问题,让帮忙查看后台日志,发现后台日志报错的信息如下: java.net.SocketException: Too many open files at java.n ...
- Apache Commons工具集简介
- mysql中根据一个字段相同记录写递增序号,如序号结果,如何实现?
mysql中根据一个字段相同记录写递增序号,如序号结果,如何实现? mysql中实现方式如下: select merchantId, NameCn, send_date, deliver_name ...
- hive的初步认识与hive的本质
Hive是什么?就从这儿开始学习.... Hive是建立在Hadoop hdfs上的数据仓库基础架构. Hive可以用来数据抽取转换加载(ETL). Hive定义了简单的类SQL查询语句,称为HQL. ...
- VS添加命令行参数main(int argc, char** argv)
- checkbox多选框选择判断
全选<input type="checkbox" name="select" id="select" value="chec ...
- Extjs6 Sdk中常用文件的作用
一.框架文件 ext.js: 压缩版. 动态加载扩展类的基础框架. ext-all.js: 压缩版. 包含框架全部类. ext-all-debug.js: 未压缩版. 包含框架全部类 ext-debu ...