John

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
http://acm.hdu.edu.cn/showproblem.php?pid=1907

Problem Description
Little John is playing very funny game with his younger
brother. There is one big box filled with M&Ms of different colors. At first
John has to eat several M&Ms of the same color. Then his opponent has to
make a turn. And so on. Please note that each player has to eat at least one
M&M during his turn. If John (or his brother) will eat the last M&M from
the box he will be considered as a looser and he will have to buy a new candy
box.

Both of players are using optimal game strategy. John starts first
always. You will be given information about M&Ms and your task is to
determine a winner of such a beautiful game.

 
Input
The first line of input will contain a single integer T
– the number of test cases. Next T pairs of lines will describe tests in a
following format. The first line of each test will contain an integer N – the
amount of different M&M colors in a box. Next line will contain N integers
Ai, separated by spaces – amount of M&Ms of i-th
color.

Constraints:
1 <= T <= 474,
1 <= N <= 47,
1
<= Ai <= 4747

 
Output
Output T lines each of them containing information
about game winner. Print “John” if John will win the game or “Brother” in other
case.

Sample Input
2
3
3 5 1
1
1
 
Sample Output
John
Brother
 
题意:Nim取石子,取到最后一个的输
若局面异或和为不为0,定义其为S态,否则,定义其为T态
若一堆石子只有1个,定义其为孤独堆,否则,定义其为充裕堆
 
S0:无充裕堆,异或和不为0
S1:有1个充裕堆,异或和不为0
S2:有>=2个充裕堆,异或和不为0
T0:无充裕堆,异或和为0
T1不存在
T2:有>=2个充裕堆,异或和为0
 
S0:一定是有奇数个孤独堆,所以必败
T0:一定是有偶数个孤独堆,必胜
S1:若孤独堆个数为奇数,则拿空充裕堆,那么留给对方的是S0态,所以S1必胜
S2:可以转到S1、T2
T2:可以转到S1、S2
若T2转到了S2,则S2有转回了T2
若T2转到了S1,则T2必败
所以S2必胜
 
#include<cstdio>
using namespace std;
int main()
{
int T,n,x,sum,yh;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
sum=yh=;
for(int i=;i<=n;i++)
{
scanf("%d",&x);
yh^=x;
if(x>) sum++;
}
if(yh&&!sum) printf("Brother\n");
else if(!yh&&sum>=) printf("Brother\n");
else printf("John\n");
}
}
 

hdu 1907 John (anti—Nim)的更多相关文章

  1. hdu 1907 John(anti nim)

    John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  2. HDU 1907 John (Nim博弈)

    John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  3. POJ 3480 &amp; HDU 1907 John(尼姆博弈变形)

    题目链接: PKU:http://poj.org/problem? id=3480 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=1907 Descri ...

  4. HDU 1907 John(博弈)

    题目 参考了博客:http://blog.csdn.net/akof1314/article/details/4447709 //0 1 -2 //1 1 -1 //0 2 -1 //1 2 -1 / ...

  5. HDU 1907 John(取火柴博弈2)

    传送门 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int ...

  6. hdu 2509 Be the Winner(anti nim)

    Be the Winner Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  7. HDU 5795 A Simple Nim(简单Nim)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  8. HDU 3533 Escape(大逃亡)

    HDU 3533 Escape(大逃亡) /K (Java/Others)   Problem Description - 题目描述 The students of the HEU are maneu ...

  9. HDU 1043 Eight(八数码)

    HDU 1043 Eight(八数码) 00 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)   Problem Descr ...

随机推荐

  1. Nginx 使用札记

    nginx是什么? nginx是俄罗斯人 Igor Sysoev为俄罗斯访问量第二的Rambler.ru站点开发的一个十分轻量级的HTTP服务器.它是一个高性能的HTTP和反向代理服务器,同时也可以作 ...

  2. DFS(DP)---POJ 1014(Dividing)

    原题目:http://poj.org/problem?id=1014 题目大意: 有分别价值为1,2,3,4,5,6的6种物品,输入6个数字,表示相应价值的物品的数量,问一下能不能将物品分成两份,是两 ...

  3. tomcat配置服务

    1.在server中右键添加tomcat 2.双击tomcat打开配置窗口添加jvm参数 -Doapath="C:\exeye-workspace\exEyeWeb\oadoc"  ...

  4. C++对象模型 多重继承与虚函数表

    一 多重继承 1) 代码: Code#include <iostream>using namespace std; class B1{public:    int x;    virtua ...

  5. 树莓派无显示器、无网线,优盘(U盘)启动,远程桌面

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:树莓派无显示器.无网线,优盘(U盘)启动,远程桌面     本文地址:http://techi ...

  6. 安恒杯-babysql

    1. 库名 ?id= and extractvalue(,(select group_concat(0x3a,schema_name) from information_schema.schemata ...

  7. 【Nginx】nginx为目录或网站加上密码认证

    第一步生成pwd用户名密码文件 工具:http://trac.edgewall.org/export/10770/trunk/contrib/htpasswd.py 步骤: chmod 777 htp ...

  8. CTSC2012-Cheat

    题意 给出一些母01串,多次询问,每次询问一个01串,问一个最大的\(L\),使得可以在询问串中选出若干个不相交的,长度大于等于\(L\)的子串,这些子串都在母串中出现过,且子串的长度和大于等于询问串 ...

  9. 【bzoj3110】[Zjoi2013]K大数查询 整体二分+树状数组区间修改

    题目描述 有N个位置,M个操作.操作有两种,每次操作如果是1 a b c的形式表示在第a个位置到第b个位置,每个位置加入一个数c.如果是2 a b c形式,表示询问从第a个位置到第b个位置,第C大的数 ...

  10. SPA页面性能优化

    1. 快速启动 —— 极大提升加载速度(important) 快速启动应用,并行发起 Bundle 加载&拉取初始数据.相信大家已经发现了,SPA 初始化时候,不得不等待 bundle 返回并 ...