John

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

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
 
n堆物品,每次从一堆中取至少一个,取到最后一个的败,John先取,Brother后取,输出胜利者的名字
这种类型的尼姆博弈,必胜态有S2,S1,T0,必败态有T2,S0,具体参考前面关于三种博弈的总结。
 
int main() {

    int T, n;
scanf("%d", &T);
while (T --) {
scanf("%d", &n);
int res = , cnt = , tmp;
for (int i = ; i <= n; i ++) {
scanf("%d", &tmp);
res ^= tmp;
if (tmp > ) cnt ++;
}
if ((res == && cnt == ) || (res && cnt)) printf("John\n");
else printf("Brother\n");
} return ;
}

最新文章

  1. VS调式显示问题
  2. [THINKING IN JAVA]复用类
  3. 推导大O阶方法
  4. (转)SQL SERVER的锁机制(四)——概述(各种事务隔离级别发生的影响)
  5. CSS禅意花园(设计一)
  6. 深入研究java.lang.Runtime类【转】
  7. 亚马逊副总裁谈Marketplace平台的个性化服务
  8. erp中三大订单CO、PO、MO各是代表什么?
  9. 【转帖】C# DllImport 系统调用使用详解 托管代码的介绍 EntryPoint的使用
  10. MYSQL存储过程中-流程控制语句
  11. oracle中 some、any、all 三者的区别及个人总结,归纳!
  12. FreeCodeCamp:Confirm the Ending
  13. Linux文件权限与目录配置
  14. 存储容量和IOPS的关系
  15. java程序设计习题总结
  16. Spring Boot使用AOP在控制台打印请求、响应信息
  17. python 爬取可用
  18. hbuilder中的wap2app (将M站快速转换成App的开发框架)使用过程有关原生标题的关闭
  19. JS sort() 方法
  20. 安卓Android基础—第一天

热门文章

  1. xamdin: 添加小组件报错: render() got an unexpected keyword argument &#39;renderer&#39;
  2. CUDA9.0+tensorflow-gpu1.8.0+Python2.7服务器环境搭建经验
  3. 预研报告——MyBatis持久层的demo
  4. DFS(5)——hdu1728逃离迷宫
  5. Xcode 自动打包之旅【本文摘自智车芯官网】
  6. 【Linux】使用 PXE+Kickstart 无人值守批量安装系统
  7. javascript 数组以及对象的深拷贝
  8. web online ide &amp;web online editor &amp; web online playground &amp; web online runtime
  9. 【bzoj4817】[Sdoi2017]树点涂色 LCT+LCA+线段树
  10. HTML5&lt;canvas&gt;标签:使用canvas元素在网页上绘制四分之一圆(3)