poj3480--John
题意:n堆石子,两人轮流操作,每次操作只能选定其中一堆,并取走若干个(>=1个)。谁取走最后一个谁输。给定一个状态,问先取的赢还是后取的赢。
整个游戏反过来,如果sg为0先手必胜,不为0必败。(特殊情况:所有堆都是1,这时候奇数堆必胜,偶数必败)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
int main(){
int T,n,x;
scanf("%d",&T);
while (T--){
int cnt=,sg=;
scanf("%d",&n);
for (int i=;i<=n;i++){
scanf("%d",&x);
if (x==) cnt++;
sg^=x;
}
if (cnt==n){
if (sg) printf("Brother\n");
else printf("John\n");
}
else{
if (sg) printf("John\n");
else printf("Brother\n");
}
}
}
poj3480--John的更多相关文章
- POJ3480 John 博弈论 anti-nim anti-SG
http://poj.org/problem?id=3480 anti-nim其实是anti-SG的一种,就像nim是sg的一种一样.(或者说sg是nim推广?) 看名字就是规则和nim相反,取到最后 ...
- John the ripper使用教程
破解Linux的用户密码:John [跨平台的密码解密工具] root@only:~# unshadow /etc/passwd /etc/shadow > ~/file_to_crack ro ...
- HDU 1907 John nim博弈变形
John Problem Description Little John is playing very funny game with his younger brother. There is ...
- Js-字符串截取substring,分割split,指标indexOf,拼接John
函数:split() 功能:使用一个指定的分隔符把一个字符串分割存储到数组例子: var theString=”jpg|bmp|gif|ico|png”; var arr=theString.spli ...
- John the Ripper
John the RipperJohn the Ripper(简称John)是一款著名的密码破解工具.它主要针对各种Hash加密的密文.它不同于Rainbow Table方式.它采用实时运算的方式和密 ...
- POJ 3683 Priest John's Busiest Day(2-SAT 并输出解)
Description John is the only priest in his town. September 1st is the John's busiest day in a year b ...
- BZOJ1022 [SHOI2008]小约翰的游戏John
Description 小约翰经常和他的哥哥玩一个非常有趣的游戏:桌子上有n堆石子,小约翰和他的哥哥轮流取石子,每个人取 的时候,可以随意选择一堆石子,在这堆石子中取走任意多的石子,但不能一粒石子也不 ...
- HDU1907 John
Description Little John is playing very funny game with his younger brother. There is one big box fi ...
- HDOJ 1907 John
对于任意一个 Anti-SG 游戏,如果我们规定当局面中所有的单一游戏的 SG 值为 0 时,游戏结束,则先手必胜当且仅当: (1)游戏的 SG 函数不为 0 且游戏中某个单一游戏的 SG 函数大于 ...
- hdu-----2491Priest John's Busiest Day(2008 北京现场赛G)
Priest John's Busiest Day Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
随机推荐
- LeetCode_Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If ...
- 在VS2010下开发C语言程序
妈蛋,我发现VS下开发C语言,并不是把文件名改成.C的就行了.VS2010不支持C99. 也就是函数局部变量声明必须放在函数的开头.难怪,我从Linux下移植过来的.c工程怎么是编译错误呢,发现是变 ...
- windows 挂载linux nfs
windwos挂载linux主机NFS 启动windos NFS客户端服务: 1. 打开控制面板->程序->打开或关闭windows功能->NFS客户端 勾选NFS客户端,即开启wi ...
- logstash tag使用说明
zjtest7-frontend:/usr/local/logstash-2.3.4/config# cat stdin04.conf input { stdin { } } filter { # d ...
- 通向码农的道路(enet开源翻译计划 一)
QQ 324186207群 enet交流技术.主要是为了研究tcp内部执行机制,欢迎大家增加探讨.小弟水平有限.翻译难免有误. . Features: ENet evolved specificall ...
- How to face setbacks
I’ve been in a bad mood since I started on the American Accent. I became even more upset when I adde ...
- iOS 8 Auto Layout界面自动布局系列5-自身内容尺寸约束、修改约束、布局动画
首先感谢众多网友的支持,最近我实在是事情太多,所以没有写太多.不过看到大家的反馈和评价,我还是要坚持挤出时间给大家分享我的经验.如果你对我写的东西有任何建议.意见或者疑问,请到我的CSDN博客留言: ...
- 并行计算基础&编程模型与工具
在当前计算机应用中,对快速并行计算的需求是广泛的,归纳起来,主要有三种类型的应用需求: 计算密集(Computer-Intensive)型应用,如大型科学project计算与数值模拟: 数据密集(Da ...
- 代码实现Layout android:layout_alignParentRight
代码实现Layout android:layout_alignParentRight 例如: android:id="@+id/account_option" android:la ...
- .net学习体会
莫名其妙学了IT,在课堂上学了C,C++,自学了C#,也做了一些网站项目,学习过程,写了厚厚的几本笔记本,却没写博文的习惯,前几天,有同学问学习.net的建议.其实我懂的也不多,也给了一些个人见解,主 ...