John

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 6000    Accepted Submission(s): 3486

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

C/C++:

 #include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <climits>
#include <iostream>
#include <algorithm>
#define INF 0x3f3f3f3f
#define LL long long
#define wzf ((1 + sqrt(5.0)) / 2.0)
using namespace std;
const int MAX = ; int n, t, num[MAX], temp; int main()
{
scanf("%d", &t);
while (t --)
{
scanf("%d", &n);
for (int i = ; i < n; ++ i)
scanf("%d", &num[i]);
sort(num, num + n);
if (num[n - ] == )
{
if (n & ) printf("Brother\n");
else printf("John\n");
continue;
}
temp = num[] ^ num[];
for (int i = ; i < n; ++ i)
temp ^= num[i];
if (temp == )
printf("Brother\n");
else
printf("John\n");
}
return ;
}

hdu 1907 John (尼姆博弈)的更多相关文章

  1. hdu 1907 (尼姆博弈)

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

  2. hdu 1849 (尼姆博弈)

    http://acm.hdu.edu.cn/showproblem.php? pid=1849 简单的尼姆博弈: 代码例如以下: #include <iostream> #include ...

  3. HDU 1907 John (Nim博弈)

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

  4. John 尼姆博弈

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

  5. HDU - 1907 John 反Nimm博弈

    思路: 注意与Nimm博弈的区别,谁拿完谁输! 先手必胜的条件: 1.  每一个小游戏都只剩一个石子了,且SG = 0. 2. 至少有一堆石子数大于1,且SG不等于0 证明: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 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  8. HDU.1850 being a good boy in spring festival (博弈论 尼姆博弈)

    HDU.1850 Being a Good Boy in Spring Festival (博弈论 尼姆博弈) 题意分析 简单的nim 博弈 博弈论快速入门 代码总览 #include <bit ...

  9. HDU 1907 John(博弈)

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

随机推荐

  1. 利用window10的Linux子系统实现docker的安装使用

    先参照 此博客 点这里 我在执行 apt installdocker.io 命令时,不能正确的安装 docker client 所以我找了下面的命令,然后执行 docker version 成功了 辅 ...

  2. opencv::直方图均衡化

    直方图均衡化 图像直方图: 是指对整个图像像在灰度范围内的像素值是指对整个图像像在灰度范围内的像素值(~)统计出现频率次数,据此生成的直方图,称为图像直方图-直方图. 直方图反映了图像灰度的分布情况. ...

  3. 如何使用代理IP进行数据抓取,PHP爬虫抓取亚马逊商品数据

    什么是代理?什么情况下会用到代理IP? 代理服务器(Proxy Server),其功能就是代用户去取得网络信息,然后返回给用户.形象的说:它是网络信息的中转站.通过代理IP访问目标站,可以隐藏用户的真 ...

  4. jQuery选择器 大于 空格 波浪线 加号

    JQuery选择器 大于 空格 波浪线 加号的区别 元素遍历 符号 说明 空格 $(‘parent child’)表示获取parent下的所有的child节点(所有的子孙). 大于号 $(‘paren ...

  5. 斯坦福机器学习课程 Exercise 习题二

    Exercise 2: Linear Regression 话说LaTex用起来好爽 Matlab代码 迭代并且画出拟合曲线 Linear regression 公式如下 hθ(x)=θTx=∑i=0 ...

  6. Java基础(十八)集合(5)Queue集合

    队列是只能在尾部添加元素,同时只能在头部删除元素的数据结构.队列的原则就是“先进先出”. Queue接口是Collection接口的最后一个子接口. Queue接口是队列接口,而Deque接口是Que ...

  7. fenby C语言 P22

    #include <stdio.h> int main(){ char array[]={'t','o','m','c','a','t'}; int i; for(i=0;i<6;i ...

  8. mysql 主从同步(转)

    教程开始:一.安装MySQL 说明:在两台MySQL服务器192.168.21.169和192.168.21.168上分别进行如下操作,安装MySQL 5.5.22  二.配置MySQL主服务器(19 ...

  9. 5、pytest -- 猴子补丁

    目录 1. 修改函数功能或者类属性 2. 修改环境变量 3. 修改字典 有时候,测试用例需要调用某些依赖于全局配置的功能,或者这些功能本身又调用了某些不容易测试的代码(例如:网络接入).fixture ...

  10. 提高首屏页面加载速度,解决vue-cli打包后单个文件过大的问题

    本教程是针对vue-cli3以上的版本,其实原理都大同小异,这个demo为vue-cli直接创建的项目,并在main.js中引入了echart.element-ui.lodash 首先看demo打包后 ...