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. 使用SeaJS实现模块化JavaScript开发(新)

    本文转自张洋,因为SeaJS更新版本很快,所以原文中很多地方不太适用,在这里发布一个更新版. 前言   SeaJS是一个遵循CommonJS规范的JavaScript模块加载框架,可以实现JavaSc ...

  2. Sublime Text 3 若干问题解决办法

    1.在高分屏下中文文件夹名显示异常问题解决办法 新买了个2K的屏,有些中文文件夹名全部变成了“口口”. 在“preferences” - "设置-用户" 添加 "dpi_ ...

  3. ajax跨域调用

    http://redsky008.iteye.com/blog/1754328 http://www.cnblogs.com/mahatmasmile/archive/2013/03/29/29895 ...

  4. bzoj 3153: Sone1 Toptree

    3153: Sone1 Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 511  Solved: 202[Submit][Status][Discuss ...

  5. [原博客] POJ 2425 A Chess Game

    题目链接题意:给定一个有向无环图(DAG),上面放有一些旗子,旗子可以重合,两个人轮流操作,每次可以把一个旗子从一个位置移动到相邻的位置,无法移动时输,询问先手是否必胜. 这道题可以把每个旗子看作单独 ...

  6. 【技术贴】Maven打包文件增加时间后缀

    构建war包,或者jar包的,时候,maven会自动增加一个版本号和时间放在jar包后面比如poi-3.9-20131115.jar这样子,但是我自己打war包,总是给我生成一个快照的后缀report ...

  7. 单片机系统与标准PC键盘的接口模块设计

    转自单片机系统与标准PC键盘的接口模块设计 概述     在单片机系统中,当输入按键较多时,在硬件设计和软件编程之间总存在着矛盾.对于不同的单片机系统需要进行专用的键盘硬件设计和编程调试,通用性差,使 ...

  8. Setup SQL Server 2008 Maintenance Plan Email Notifications

    一条龙作完,如何设置EXCHANGE的操作员邮件通知.. ~~~~ http://808techblog.com/2009/07/setup-sql-server-2008-maintena.html ...

  9. 【Uvalive 5834】 Genghis Khan the Conqueror (生成树,最优替代边)

    [题意] 一个N个点的无向图,先生成一棵最小生成树,然后给你Q次询问,每次询问都是x,y,z的形式, 表示的意思是在原图中将x,y之间的边增大(一定是变大的)到z时,此时最小生成数的值是多少.最后求Q ...

  10. 【Xamarin挖墙脚系列:Xamarin的核心】

    原文:[Xamarin挖墙脚系列:Xamarin的核心] Xamarin 包含两个商业产品 :Xamarin.IOS, Xamarin.Android.他们都是通过开源的基于.Net的Mono项目构建 ...