John

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.

InputThe 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

OutputOutput 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
对于N堆的糖,一种情况下是每堆都是1,那么谁输谁赢看堆数就知道;
对于不都是1的话,若这些堆是奇异局势,或说他们是非奇异局势,但非奇异局势皆可以转换到奇异局势。 经典的尼姆问题是谁哪拿到最后一个则谁赢,本题是拿最后一个的输。
下面分析第二种情况:
1.初始给的是奇异局势的话,则先取者拿到最后一个为输。
2.初始给的是非奇异局势的话,则先取者为赢。
对于任何奇异局势(a,b,c),都有a^b^c=0(^是代表异或).
非奇异局势(a,b,c)(a<b<c)转换为奇异局势,只需将c变成a^b,即从c中减去c-(a^b)即可
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args){

        int t, n, x, f, ans, i;
t = sc.nextInt();
while((t--) != 0){
n = sc.nextInt();
ans = 0; f = 0;
for(i = 1; i <= n; i++){
x = sc.nextInt();
ans ^= x;
if(x > 1) f = 1;
}
if(f == 0){
if((n & 1) != 0) System.out.println("Brother");
else System.out.println("John");
}
else{
if(ans == 0) System.out.println("Brother");
else System.out.println("John");
}
}
}
}

John 尼姆博弈的更多相关文章

  1. hdu 1907 John (尼姆博弈)

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

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

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

  3. hdu 1907 (尼姆博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1907 Problem Description Little John is playing very ...

  4. HDU1907(尼姆博弈)

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

  5. hdu 1907 尼姆博弈

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

  6. hdu1907 尼姆博弈

    尼姆博弈的性质. 最后一个取输.若a1^a2^a3...^a4=0表示利他态T,不然为利己态S.充裕堆:1个堆里的个数大于2.T2表示充裕堆大于等于2,T1表示充裕堆大于等于1,T0表示无充裕堆.S2 ...

  7. hdu----(1849)Rabbit and Grass(简单的尼姆博弈)

    Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. hdu 1849(Rabbit and Grass) 尼姆博弈

    Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. Being a Good Boy in Spring Festival 尼姆博弈

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Descr ...

随机推荐

  1. 九度OJ 1163:素数 (素数)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:8496 解决:2887 题目描述: 输入一个整数n(2<=n<=10000),要求输出所有从1到这个整数之间(不包括1和这个整数 ...

  2. svn服务器 vim 修改 authz passwd 添加用户

    进入svn服务器 vim 修改 authz passwd 添加用户 SVN服务器之------2,配置PhpStorm连接SVN服务器(其他IDE大同小异) - 学到老死 - 博客园 https:// ...

  3. 如何在ubuntun中安装pycharm并将图标显示在桌面上

    安装pycharm首先要安装jdk. 可以通过java -V来查看是否安装了jdk.安装jdk的方法如下: 1 首先在oracle网站下载jdk,现在jdk是1.8的. 2 新建一个/usr/lib/ ...

  4. 05-树8 File Transfer(25 point(s)) 【并查集】

    05-树8 File Transfer(25 point(s)) We have a network of computers and a list of bi-directional connect ...

  5. BZOJ 2142 礼物 数论

    这道题是求组合数终极版. C(n,m) mod P n>=1e9 m>=1e9 P>=1e9且为合数且piqi<=1e5 拓展lucas定理. 实际上就是一点数论小知识的应用. ...

  6. 深入浅出理解linux inode结构【转】

    本文转载自:https://blog.csdn.net/fantasyhujian/article/details/9151615 一.inode是什么? 参考文档:http://tech.diann ...

  7. 应用程序无法启动(0*c000007b)

    2个插件就解决  一个是DX缺失工具检查那个 一个是运行库缺失检查

  8. VC++共享文件夹

    BOOL NetShare(char * pShareName,char * pSharePath) { USES_CONVERSION; SHARE_INFO_502 si502; NET_API_ ...

  9. Redis常用数据结构和操作

    1.String 存入字符类型 Set name luowen 设置name = luowen 存储 Get name 获取设置好的name的值 Setnx name luowen 设置name键值为 ...

  10. html5常用模板下载网站

    html5常用模板下载网站 开创者素材.站长素材.模板之家 推荐葡萄家园素材网,他们网页模板栏目有个HTML模板,很多静态源码.应该是你所需要的. html静态页面模板 还是服饰素材啊 朋友 设计云 ...