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 no te 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.

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. 
Constrains: 
1 <= T <= 474, 
1 <= N <= 47, 
1 <= Ai <= 4747

Sample Input

2
3
3 5 1
1
1

Sample Output

John
Brother

分析:博弈题,最后拿者输!

代码:

#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
int main()
{
//freopen("a.in","r",stdin);
//freopen("aa.out","w",stdout);
int t,n,i,in,cnt,ans;
while(scanf("%d",&t)!=EOF)
{
while(t--)
{
scanf("%d",&n);
cnt=0;ans=0;
for(i=0;i<n;i++)
{
scanf("%d",&in);
if(in==1)
cnt++;
ans^=in;
}
if(cnt==n)
{
printf("%s\n",(cnt%2!=1)?"John":"Brother");
continue;
}
if(ans!=0)
printf("John\n");
else
printf("Brother\n");
}
}
return 0;
}

John(博弈)的更多相关文章

  1. hdu1907 John 博弈

    Little John is playing very funny game with his younger brother. There is one big box filled with M& ...

  2. POJ 3480 John [博弈之Nim 与 Anti-Nim]

    Nim游戏:有n堆石子,每堆个数不一,两人依次捡石子,每次只能从一堆中至少捡一个.捡走最后一个石子胜. 先手胜负:将所有堆的石子数进行异或(xor),最后值为0则先手输,否则先手胜. ======== ...

  3. 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 ...

  4. HDU - 1907 John 反Nimm博弈

    思路: 注意与Nimm博弈的区别,谁拿完谁输! 先手必胜的条件: 1.  每一个小游戏都只剩一个石子了,且SG = 0. 2. 至少有一堆石子数大于1,且SG不等于0 证明:1. 你和对手都只有一种选 ...

  5. POJ 3480 John(SJ定理博弈)题解

    题意:n堆石头,拿走最后一块的输 思路:SJ定理:先手必胜当且仅当:(1)游戏的SG函数不为0且游戏中某个单一游戏的SG函数大于1:(2)游戏的SG函数为0且游戏中没有单一游戏的SG函数大于1. 参考 ...

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

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

  7. HDU 1907 John(博弈)

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

  8. bzoj1022: [SHOI2008]小约翰的游戏John(博弈SG-nim游戏)

    1022: [SHOI2008]小约翰的游戏John 题目:传送门 题目大意: 一道反nim游戏,即给出n堆石子,每次可以取完任意一堆或一堆中的若干个(至少取1),最后一个取的LOSE  题解: 一道 ...

  9. HDU 1907 John nim博弈变形

    John Problem Description   Little John is playing very funny game with his younger brother. There is ...

随机推荐

  1. 关于js小数计算的问题

    在js浮点运算中 var a=0.2-0.1; var b=0.3-0.2; console.log(a==b); 答案是什么呢,很多人可能认为是true,包括我在内,但是当我写出来运行了一下,我被答 ...

  2. SQL Express几个版本的区别

    对于这三个文件:SQLEXPR32_x86_CHS.exe.SQLEXPR_x86_CHS.exe. SQLEXPR_x64_CHS.exe,大家一看就知道是sqlserver的express版本,但 ...

  3. 用Thread类创建线程-2

    支持原创,本系列文章均转自:http://www.blogjava.net/nokiaguy/category/38172.html 在Java中创建线程有两种方法:使用Thread类和使用Runna ...

  4. BZOJ 1642: [Usaco2007 Nov]Milking Time 挤奶时间

    Description 贝茜是一只非常努力工作的奶牛,她总是专注于提高自己的产量.为了产更多的奶,她预计好了接下来的N (1 ≤ N ≤ 1,000,000)个小时,标记为0..N-1. Farmer ...

  5. 在Eclipse中安装ADT

    启动 Eclipse,然后选择 Help > Software Updates….在出现的对话框中,单击 Available Software 选项卡. 单击 Add Site 在 Add Si ...

  6. DZ真是各种强大

    近期对论坛做了大装修,非常享受这个过程. 真是着迷了,这个装修工程让我接连几天几乎到了废寝忘食的地步. 终于告一段落,又想起来折腾,因为对之前的文库系统感觉种种别扭. 没有空调,没有风扇,居然忙到夜里 ...

  7. 修改PHP上传大小设置

    目前文档文库上传大小是读取服务器的PHP环境的设置,你们的PHP环境上传限制是多少,这里显示的就是多少. 很多用户问我如何修改上传大小,自己可以百度一下方法,也可以根据以下步骤修改: 1.找到服务务器 ...

  8. Python模块subprocess小记

    转自:http://www.oschina.net/question/234345_52660 熟悉了Qt的QProcess以后,再回头来看python的subprocess总算不觉得像以前那么恐怖了 ...

  9. 【UVA 1151】 Buy or Build (有某些特别的东东的最小生成树)

    [题意] 平面上有n个点(1<=N<=1000),你的任务是让所有n个点连通,为此,你可以新建一些边,费用等于两个端点的欧几里得距离的平方. 另外还有q(0<=q<=8)个套餐 ...

  10. Android ListView中 每一项都有不同的布局

    实现代码 Adapter的代码 其中:ViewHolder分别是三个不同的布局,也就是ListView中每一项的布局 TYPE_1...是三种类型. 在使用不同布局的时候,getItemViewTyp ...