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. android菜鸟学习笔记15----Android Junit测试

    Android中的Junit测试与Java Junit测试有所不同,不能简单的使用标注…… 假设写了一个MathUtils类,有两个静态方法: public class MathUtils { pub ...

  2. centos 安装postgresql 完整版

    按步骤 执行命令即可: yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-c ...

  3. spring-boot3代码

    App.java package com.kfit; import org.springframework.boot.SpringApplication; import org.springframe ...

  4. (linux)BSP(板上支持包)概述

    1. BSP概述 BSP即Board Support Package,板级支持包. 它来源于嵌入式操作系统与硬件无关的设计思想,操作系统被设计为运行在虚拟的硬件平台上. 对于具体的硬件平台,与硬件相关 ...

  5. jQuery 3D旋转展示焦点图

    在线演示 本地下载

  6. vue 升降排序

    本实例是根据工作进度的百分比来进行排序. html <div class="ibox-content"> <li v-for="(rangeItem,i ...

  7. Zookeeper原理与Curator使用

    近期打算实现一个基于Zookeeper的分布式的集群状态一致性控制, 对Zookeeper的原理不太了解, 正好学习一下, 网上找到了几篇文章, 先贴在这边, 等我熟读官方文档后, 再来补充自己的见解 ...

  8. cocos2d-x中CCScrollView纵向展示

    最近写CCScrollView遇到很多问题,样式是竖直的类似tableview,在此记录下: CCLayer* layer; 初始化scrollview内容器层 layer = CCLayer::cr ...

  9. laravel基础课程---4、Laravel基础网站结构搭建

    laravel基础课程---4.Laravel基础网站结构搭建 一.总结 一句话总结: 1.搭建网站前后台路由:在路由组Route::group()中设置好命名空间和前缀 2.搭建控制器:比如1)新建 ...

  10. sublime 3好用快捷键

    sublime 3好用快捷键 自己常用 删除行 [ { "keys": ["ctrl+shift+d"], "command": " ...