John

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

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
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  1913 1908 1914 1915 1909 
 
题意大概是有n种颜色的糖豆,john和他的哥哥轮流吃糖,每次可以选择其中的一种颜色中的若干个,最后谁最后吃完谁就输了
思路:
经典的尼姆博弈问题
对于尼姆博弈,类似于威佐夫博弈,奇异局势与非奇异局势碾转变换,先发者如果面对的奇异局势则输,反之则胜
对于如果判断面对的局势是否为奇异局势,有两种情况需要考虑
1  如果所有项都为1的话,只需要判断奇偶的数量就可以了
2  若不为1的情况,如果所有数的异或值为0,那么就是奇异局势,否则不是奇异局势
 
代码1a,
可做模板
重试信心-------》-----》
#include<stdio.h>
#include<string.h>
#include<math.h>
int a[]; int main(){
int t;
scanf("%d",&t);
int n;
while(t--){
scanf("%d",&n);
bool flag=true;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]!=)
flag=false;
}
int ans=a[];
for(int i=;i<=n;i++)
ans=ans^a[i]; if(flag){
if(n%)
printf("Brother\n");
else
printf("John\n"); }
else{
if(ans)
printf("John\n");
else
printf("Brother\n");
} }
return ;
}

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

  1. hdu 1850(尼姆博弈)

    Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32 ...

  2. hdu 1907 (尼姆博弈)

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

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

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

  4. hdu 1849 (尼姆博弈)

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

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

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

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

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

  7. HDU 4315 Climbing the Hill (阶梯博弈转尼姆博弈)

    Climbing the Hill Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Su ...

  8. HDU 2176 取(m堆)石子游戏 尼姆博弈

    题目思路: 对于尼姆博弈我们知道:op=a[1]^a[2]--a[n],若op==0先手必败 一个简单的数学公式:若op=a^b 那么:op^b=a: 对于第i堆a[i],op^a[i]的值代表其余各 ...

  9. 题解报告:hdu 1850 Being a Good Boy in Spring Festival(尼姆博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1850 Problem Description 一年在外 父母时刻牵挂春节回家 你能做几天好孩子吗寒假里 ...

随机推荐

  1. Windows下Apache+PHP+MySQL开发环境的搭建(WAMP)

    准备工作: 1.下载apache服务器安装包,官网http://www.apache.org/,下载地址:http://httpd.apache.org/download.cgi 2.下载MySQL, ...

  2. 解决部分浏览器不能显示itext生成的PDF文件文本域内容问题

    利用Itext可以实现pdf的高效动态生成,但在实践过程中遇到了一个问题: 即itext利用map中的值设置到pdf模板上建立的文本域中时:能成功生成,但是在部分浏览器上(360,QQ,等浏览器)无法 ...

  3. 洛谷 P1926 小书童——刷题大军

    题目背景 数学是火,点亮物理的灯:物理是灯,照亮化学的路:化学是路,通向生物的坑:生物是坑,埋葬学理的人. 文言是火,点亮历史宫灯:历史是灯,照亮社会之路:社会是路,通向哲学大坑:哲学是坑,埋葬文科生 ...

  4. 洛谷 P1009 阶乘之和

    题目描述 用高精度计算出S=1!+2!+3!+…+n!(n≤50) 其中“!”表示阶乘,例如:5!=5*4*3*2*1. 输入输出格式 输入格式: 一个正整数N. 输出格式: 一个正整数S,表示计算结 ...

  5. 洛谷 P1276 校门外的树(增强版)

    题目描述 校门外马路上本来从编号0到L,每一编号的位置都有1棵树.有砍树者每次从编号A到B处连续砍掉每1棵树,就连树苗也不放过(记 0 A B ,含A和B):幸运的是还有植树者每次从编号C到D 中凡是 ...

  6. Caused by: java.lang.ClassNotFoundException: org.springframework.boot.system.JavaVersion

    Caused by: java.lang.ClassNotFoundException: org.springframework.boot.system.JavaVersion Invalid pro ...

  7. afnetworking NSCocoaErrorDomain Code=3840 解决

    afnetworking json解析出错 解决方法1 AFURLResponseSerialization.m 258行修改 responseString = [responseString str ...

  8. build.sbt的定义格式

    一个简单的build.sbt文件内容如下: name := "hello" // 项目名称 organization := "xxx.xxx.xxx" // 组 ...

  9. python基础一 day13 生成器

    #生成器函数# def generator():# print(1)# return 'a'## ret = generator()# print(ret) #只要含有yield关键字的函数都是生成器 ...

  10. webpack之postcss集成

    项目 为了 兼容各个浏览器,需要加各种 c3前缀,如果手动的加肯定 相对比较麻烦,但是现在有webpack,gulp之类的 工具可以自动给我们加上,可以说效率上加速不少.如果 配置中 做个happyp ...