John

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

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
 
    对于所有不同颜色M&M的个数都为1的情况,显然:
       if(sg==0)  win       -->状态A
    if(sg!=0)   lose       -->状态B
   对于对立情况,
    当数量不为1的种类只有一种的时候(状态C),显然先手总可以将其转化到状态B这个败态,所以C是胜态。
    当数量不为1的种类大于1的时候,分为sg=0(状态D)和sg!=0(状态E)两种情况,D只能转化到E,E能转化到D或者
C,由于C是败态,所以E尽可能向D转化,但随着石子的不断减少导致E只能转化到C,所以E是败态,D是胜态。
  
  

 #include<bits/stdc++.h>
using namespace std;
int main(){
int t,n,m;
cin>>t;
while(t--){
int a,sg=,tot=;
cin>>n;
for(int i=;i<=n;++i){
cin>>a;
sg^=a;
if(a==) tot++;
}
if( (tot==n&&sg==) || (tot!=n&&sg!=)) puts("John");
else puts("Brother");
}
return ;
}

hdu-1907-反nim博弈的更多相关文章

  1. HDU 1907 John nim博弈变形

    John Problem Description   Little John is playing very funny game with his younger brother. There is ...

  2. hdu2509Be the Winner(反nim博弈)

    Be the Winner Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  3. hdu1907John(反nim博弈)

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

  4. LightOJ 1253 Misere NIM(反NIM博弈)

    Alice and Bob are playing game of Misère Nim. Misère Nim is a game playing on k piles of stones, eac ...

  5. 反Nim博弈

    原文地址:https://blog.csdn.net/xuejye/article/details/78975900 在尼姆博奕中取完最后一颗糖的人为赢家,而取到最后一颗糖为输家的就是反尼姆博奕.这道 ...

  6. hdu 1907 尼姆博弈

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

  7. HDU 1907 John(博弈)

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

  8. 博弈论中的Nim博弈

    瞎扯 \(orzorz\) \(cdx\) 聚聚给我们讲了博弈论.我要没学上了,祝各位新年快乐.现在让我讲课我都不知道讲什么,我会的东西大家都会,太菜了太菜了. 马上就要回去上文化课了,今明还是收下尾 ...

  9. HDU 1907 Nim博弈变形

    1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...

  10. hdu 1907 John&& hdu 2509 Be the Winner(基础nim博弈)

    Problem Description Little John is playing very funny game with his younger brother. There is one bi ...

随机推荐

  1. 在 Linux 中使用超级用户权限

    在你想要使用超级权限临时运行一条命令时,sudo 命令非常方便,但是当它不能如你期望的工作时,你也会遇到一些麻烦.比如说你想在某些日志文件结尾添加一些重要的信息,你可能会尝试这样做: $ echo & ...

  2. P4180 【模板】严格次小生成树[BJWC2010]

    P4180 [模板]严格次小生成树[BJWC2010] 倍增(LCA)+最小生成树 施工队挖断学校光缆导致断网1天(大雾) 考虑直接枚举不在最小生成树上的边.但是边权可能与最小生成树上的边相等,这样删 ...

  3. SIFT在OpenCV中的调用和具体实现(HELU版)

    前面我们对sift算法的流程进行简要研究,那么在OpenCV中,sift是如何被调用的?又是如何被实现出来的了? 特别是到了3.0以后,OpenCV对特征点提取这个方面进行了系统重构,那么整个代码结构 ...

  4. 20145122 《Java程序设计》课程总结

    课程总结 每周读书笔记链接汇总 第一周读书笔记:http://www.cnblogs.com/20145122chengzhiyin/p/5244949.html 第二周读书笔记:http://www ...

  5. 2018-2019-1 20189218《Linux内核原理与分析》第九周作业

    进程调度的时机 进程调度时机就是内核调用schedule函数的时机.当内核即将返回用户空间时,内核会检查need_resched标志是否设置.如果设置,则调用schedule函数,此时是从中断(或者异 ...

  6. 对于phy芯片的认识

    一,关于phy芯片 以RTL8211E(G)为例 PHY是IEEE802.3中定义的一个标准模块,STA(station management entity,管理实体,一般为MAC或CPU) 通过SM ...

  7. 认识epoll

    linux下的epoll(7)函数,其有着良好的就绪事件通知机制.Epoll 是被linux2.6开始引进的,但是不被其他的类UNIX系统支持,它提供了一种类似select或poll函数的机制:a. ...

  8. PHP中namespace和use使用详解

    来源于:http://www.jb51.net/article/36389.htm 命名空间一个最明确的目的就是解决重名问题,PHP中不允许两个函数或者类出现相同的名字,否则会产生一个致命的错误.这种 ...

  9. Msys2的安装,并整合到cmder中

    下载:msys2-x86_64-20161025.exe 下载安装包,然后装上. 打开msys的shell之后首先升级一下pacman,然后就可以愉快地Syu了. $ pacman -Sy pacma ...

  10. Hive创建内部表、外部表

    使用hive需要hive环境 启动Hive 进入HIVE_HOME/bin,启动hive ./hive 内部表 建表 hive> create table fz > (id int,nam ...