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. 20172332『Java程序设计』课程结对编程练习_四则运算第二周阶段总结

    20172313『Java程序设计』课程结对编程练习_四则运算第二周阶段总结 小组成员 20172326康皓越 20172313余坤澎 20172332于欣月 小组编程照片 设计思路 设计一个生成符号 ...

  2. 解决:Invalid character found in the request target.The valid characters are defined in RFC 7230 and RFC3986

    目录 背景 原因分析 处理方法 参考 背景 在将tomcat升级到7.0.81版后,发现系统的有些功能不能使用了,查询日志发现是有些地址直接被tomcat认为存在不合法字符,返回HTTP 400错误响 ...

  3. CentOS7安装Consul集群

    1.准备4台服务器 linux1 192.168.56.101 linux2 192.168.56.102 linux3 192.168.56.103 linux4 192.168.56.104 2. ...

  4. 自己编写 Oracle 分页函数

    CREATE OR REPLACE PACKAGE PACK_PAGINATION AS PAGESIZE CONSTANT ; TYPE TYRECORD_EMP IS RECORD( EMPNO ...

  5. phpcms 发布时间 更新 时间

  6. ConcurrentHashMap原理分析(1.7与1.8)-put和 get 需要执行两次Hash

    ConcurrentHashMap 与HashMap和Hashtable 最大的不同在于:put和 get 两次Hash到达指定的HashEntry,第一次hash到达Segment,第二次到达Seg ...

  7. Java容器深入浅出之List、ListIterator和ArrayList

    List是Collection接口的子接口,表示的是一种有序的.可重复元素的集合. List接口的主要实现类ArrayList和Vector,底层都是维护了一套动态的,可扩展长度的Object[]数组 ...

  8. Graph-Based image segmentation method

    1.Graph-Based 方法简介 基于图的图像分割方法将图像伪造成带权值无向图的形式 : G = (V, E) 其中,V是顶点集合,把图像中的每个像素或者每个区域看成图的一个顶点:E是边的集合,连 ...

  9. python的N个小功能(更新文件)

    ########################################################################## #对于第二份文件:第一份与第二份不相同,以第二份为 ...

  10. 中小型园区网络的基本部署之动手划分vlan

    在计算机网络中,一个二层网络可以被划分为多个不同的广播域,一个广播域对应了一个特定的用户组,默认情况下这些不同的广播域是相互隔离的.不同的广播域之间想要通信,需要通过一个或多个路由器.这样的一个广播域 ...