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. css 动画animation基本属性(干货)

    /* 动画名称 */ animation-name: cloud; /* 属性定义动画完成一个周期所需要的时间,以秒或毫秒计 */ animation-duration:1s; /* 属性定义动画何时 ...

  2. ThinkPHP<6.0 SQL注入代码审计分析

    版本过多只分析大版本和使用人数较多的版本目前使用人数最多的3.2.3.审计时也是发现多个版本未公开漏洞 测试环境:  Mysql5.6/PHP5.5 首先明确的是在不使用PDO做参数绑定时ThinkP ...

  3. Arduino学习笔记④ 经典按键实验

    1.前言     我们讲了数字IO口介绍以及做了流水灯演示(主要用到IO口的输出功能),这节课我们讲解一下IO口的输入功能,说到输入功能,最经典的例子莫过于按键实验.废话少说,赶紧上车. 2.实验材料 ...

  4. scrollWidth、clientWidth 和 offsetWidth

    scrollWidth:对象的实际内容宽度,不包括边线宽度,会随对象中内容超过可视区而变大. clientWidth:对象内容的可视区的宽度,不包括边线宽度,会随对象显示大小的变化而变化. offse ...

  5. c# winform用sharpGL(OpenGl)解析读取3D模型obj

    原文作者:aircraft 原文链接:https://www.cnblogs.com/DOMLX/p/11783026.html 自己写了个简单的类读取解析obj模型,使用导入类,然后new个对象,在 ...

  6. python wraps的作用

    1.__name__用来显示函数的名称,__doc__用来显示文档字符串也就是("""文档字符串""")这里面的内容 2.首先我们来看不加@ ...

  7. js循环和调用

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. docker 概念简介、简单入门

    1.docker 简介 Docker 是一个开源项目,这个项目旨在通过把应用程序打包为可移植的.自给自足的容器(引用语) DocKer一次构建可放在任何地方就可以运行,不需要进行任何改变DocKer  ...

  9. open_basedir限制目录

    1.open_basedir介绍 前言:前些日我用lnmp一键安装包出现了open_basedir的问题,因为我把项目目录变了,所以要在的fastcgi.conf下面加上open_basedir的目录 ...

  10. 明解C语言 入门篇 第四章答案

    练习4-1 #include <stdio.h> int main(void) { int no; int x; do{ printf("请输入一个整数:"); sca ...