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

题意:多个人玩石头剪刀布分成3组和一个裁判,每一组提前选定了自己出哪个手势,裁判可以随意出什么手势,问是否能够从给出的一系列石头剪刀布游戏中判断出哪个是裁判的,可以从第几局游戏中判断出来。

由于这题的数据量比较小可以枚举一下,枚举一下每一个人假设他们是裁判然后一系列并查集下来看

有没有出现矛盾如果没有那么这个人可能是裁判候补,如果有矛盾那么这个人肯定不是记录一下出现

问题的位置然后继续枚举。位置要去最远的,因为都要判完才知道。如果最后没有矛盾的数目大于2

说明不能确定裁判是谁,如果为0就不可能,其他则是

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int n , m , f[510] , root[510];
struct TnT {
int x , y;
char cp;
}node[2010];
void init() {
for(int i = 0 ; i < n ; i++) {
f[i] = i , root[i] = 0;
}
}
int find(int x) {
if(x == f[x])
return x;
int tmp = find(f[x]);
root[x] = (root[x] + root[f[x]] + 3) % 3;
return f[x] = tmp;
}
int main() {
int x , y;
char s[20] , cp;
while(scanf("%d%d" , &n , &m) != EOF) {
for(int j = 1 ; j <= m ; j++) {
scanf("%s" , s);
int len = strlen(s) , temp = 0;
x = 0 , y = 0;
for(int i = 0 ; i < len ; i++) {
if(s[i] == '=' || s[i] == '<' || s[i] == '>') {
temp = i;
cp = s[i];
break;
}
}
for(int i = 0 ; i < temp ; i++) {
x *= 10;
x += s[i] - '0';
}
for(int i = temp + 1 ; i < len ; i++) {
y *= 10;
y += s[i] - '0';
}
node[j].x = x , node[j].y = y , node[j].cp = cp;
}
int count = 0 , pos = 0 , flag = -1 , num = 0;
for(int i = 0 ; i < n ; i++) {
flag = -1;
init();
for(int j = 1 ; j <= m ; j++) {
if(node[j].x == i || node[j].y == i)
continue;
x = node[j].x , y = node[j].y , cp = node[j].cp;
int a = find(x) , b = find(y);
if(a == b) {
if(cp == '=') {
if(root[x] != root[y]) {
flag = j;
break;
}
}
if(cp == '>') {
if(root[x] != (root[y] + 2) % 3) {
flag = j;
break;
}
}
if(cp == '<') {
if(root[x] != (root[y] + 1) % 3) {
flag = j;
break;
}
}
}
else {
f[a] = b;
if(cp == '=') {
root[a] = root[y] - root[x];
root[a] = (root[a] + 3) % 3;
}
if(cp == '>') {
root[a] = root[y] - root[x] + 2;
root[a] = (root[a] + 3) % 3;
}
if(cp == '<') {
root[a] = root[y] - root[x] + 1;
root[a] = (root[a] + 3) % 3;
}
}
}
if(flag == -1) {
num = i;
count++;
}
else
pos = max(pos , flag);
}
if(count == 0) printf("Impossible\n");
else if(count >= 2) printf("Can not determine\n");
else
printf("Player %d can be determined to be the judge after %d lines\n" , num , pos);
}
return 0; }

最新文章

  1. Android -- 软键盘
  2. How to configure a static IP address on CentOS 7(CentOS7静态IP地址设置)
  3. (三)play之yabe项目【数据模型】
  4. org.springframework.web.context.ContextLoaderListener
  5. Python之测试webservice接口
  6. MS10_087漏洞学习研究
  7. Java基础类库简介
  8. 2018-2019 ACM-ICPC, Asia East Continent Finals部分题解
  9. linux下Flask框架搭建简单网页
  10. ActiveX IE保护模式下的低权限操作路径及Windows操作系统特殊路径
  11. 2. 感知机(Perceptron)基本形式和对偶形式实现
  12. python里面有人写while 循环用 用while 1 和while True的区别
  13. winform窗体程序运行后怎样隐藏?
  14. aop的概述
  15. Pytorch相关内容
  16. ros nodelet 使用
  17. 洛谷P2657 [SCOI2009]windy数 [数位DP,记忆化搜索]
  18. Codeforces Round #307 (Div. 2)
  19. Json的简单介绍和解析
  20. Getting Started with xUnit.net (desktop)

热门文章

  1. ue4使用SceneCapture2D创建小地图示例 蓝图
  2. Extjs的使用总结笔记
  3. POI导入excel
  4. 树莓派 + Windows IoT Core 搭建环境监控系统
  5. Android--SharedPreferences数据存储方案
  6. 高性能MySQL之基础架构
  7. Netty学习(四)-TCP粘包和拆包
  8. JavaWeb——JSP开发1
  9. docker/kubernetes国内源/镜像源解决方式
  10. Spring基础笔记