HDU - 1907 John 反Nimm博弈
思路: 注意与Nimm博弈的区别,谁拿完谁输!
先手必胜的条件:
1. 每一个小游戏都只剩一个石子了,且SG = 0.
2. 至少有一堆石子数大于1,且SG不等于0
证明:1. 你和对手都只有一种选择,随便怎么拿,你都赢了
2. a:如果只有一堆石子数量大于1,那么你赢了,你可以拿完使得整个游戏的1的数量不变,剩余1个整个游戏1的数量增加。
b:如果至少有两堆石子数大于1,那么你可以让SG变为0,令对手处于P态,并且当前至少有两堆数量大于1,对手无论怎么拿SG都会变成非0.
结论:当石子数量全为1时,且SG=1必输,当石子数有大于两堆的石子数量大于2,且SG!=0,必输,其他情况都是必赢。
AC代码
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <utility>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#define eps 1e-10
#define inf 0x3f3f3f3f
#define PI pair<int, int>
typedef long long LL;
const int maxn = 1e4 + 5;
void in(int &a) {
char ch;
while((ch=getchar()) < '0' || ch >'9');
for(a = 0; ch >= '0' && ch <= '9'; ch = getchar()) {
a = a * 10 + ch - '0';
}
}
int main() {
int T, n;
scanf("%d", &T);
while(T--) {
in(n);
int res = 0, x, cnt = 0;
for(int i = 0; i < n; ++i) {
in(x);
res ^= x;
if(x > 1) ++cnt;
}
if(cnt == 0 && res || !res && cnt >= 2) printf("Brother\n");
else printf("John\n");
}
return 0;
}
如有不当之处欢迎指出!
HDU - 1907 John 反Nimm博弈的更多相关文章
- HDU 1907 John (Nim博弈)
John Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submis ...
- hdu 1907 John (尼姆博弈)
John Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submis ...
- nyoj888 取石子(九) 反Nimm博弈
这题就是反Nimm博弈--分析见反Nimm博弈 AC代码 #include <cstdio> #include <cmath> #include <algorithm&g ...
- POJ 3480 & HDU 1907 John(尼姆博弈变形)
题目链接: PKU:http://poj.org/problem? id=3480 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=1907 Descri ...
- hdu 1907 John&& hdu 2509 Be the Winner(基础nim博弈)
Problem Description Little John is playing very funny game with his younger brother. There is one bi ...
- HDU 1907 John(博弈)
题目 参考了博客:http://blog.csdn.net/akof1314/article/details/4447709 //0 1 -2 //1 1 -1 //0 2 -1 //1 2 -1 / ...
- HDU 1907 John nim博弈变形
John Problem Description Little John is playing very funny game with his younger brother. There is ...
- HDU 1907 John(取火柴博弈2)
传送门 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int ...
- hdu 1907 (尼姆博弈)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1907 Problem Description Little John is playing very ...
随机推荐
- python 中 reversed()函数
一个列表a: a=[1,2,3,4,5,6,7] 一个对象b: b=reversed(a) 输出: print(b) <list_reverseiterator object at 0x0000 ...
- SQL 优化经验总结34条(转)
(1) 选择最有效率的表名顺序(只在基于规则的优化器中有效): ORACLE 的解析器按照从右到左的顺序处理FROM子句中的表名,FROM子句中写在最后的表(基础表 driving table)将被最 ...
- linkin大话数据结构--Queue
链表(Linked list)是一种常见的基础数据结构,是一种线性表,但是并不会按线性的顺序存储数据,而是在每一个节点里存到下一个节点的指针(Pointer).由于不必按顺序存储,所以插入和删除速度超 ...
- Jquery实现弹出层效果
<script type="text/javascript"> $(document).ready(function(){ $('.one').click(functi ...
- 溢出问题:overflow后最后一排文字显示不全
溢出字体会显示在padding区域(http://www.divcss5.com/css-hack/c680.shtml) section#xinwen li a h3{ border-bottom: ...
- js面向对象之继承那点事儿根本就不是事
继承 说道这个继承,了解object-oriented的朋友都知道,大多oo语言都有两种,一种是接口继承(只继承方法签名):一种是实现继承(继承实际的方法) 奈何js中没有签名,因而只有实现继承,而且 ...
- find与tar的结合使用
新建一个文件,自定义时间点[root@nhserver2 ~]# touch -t 1403010000.00 file1.txt 新建一个文件,自定义时间点[root@nhserver2 ~]# ...
- Sonar项目主要指标以及代码坏味道详解
更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢! 原文链接:http://www.cnblogs.com/zishi/p/6766994.html 众所周知Sona ...
- vsftp实现只能上传不能下载、删除权限配置
vsftpd可以对每个用户特别限制.只要给那个用户建立一个设置文件,然后在文件里设置 在vsftpd.conf里加user_config_dir=/etc/vsftpd/vsftpd_user_con ...
- 洛谷 [P2756] 飞行员配对方案问题
二分图匹配裸题 可以用匈牙利做,简单高效 输出具体的匹配路径时 ,直接输出match数组即可 #include <iostream> #include <cstdio> #in ...