hdu 1907 John(anti nim)

时间:2022-08-31 13:58:14

John

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

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
 
 
 #include <bits/stdc++.h>
using namespace std; int main()
{
int t;
int n;
int a;
int i;
int sum, ones; scanf("%d", &t); while (t--) {
scanf("%d", &n);
sum = , ones = ;
for (i = ; i < n; ++i) {
scanf("%d", &a);
sum ^= a;
if (a == ) {
++ones;
}
} //win : t0, s1, s2
//lose : s0, t2
if (sum == ) {//t
if (n - ones == ) {//t0
printf("John\n");
} else {//t2
printf("Brother\n");
}
} else {//s
if (n - ones == ) {//s0
printf("Brother\n");
} else {//s1, s2
printf("John\n");
}
}
} return ;
}

hdu 1907 John(anti nim)的更多相关文章

  1. hdu 1907 John (anti—Nim)

    John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)http://acm.h ...

  2. HDU 1907 John (Nim博弈)

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

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

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

  4. HDU 1907 John(博弈)

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

  5. HDU 1907 John(取火柴博弈2)

    传送门 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int ...

  6. hdu 2509 Be the Winner(anti nim)

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

  7. HDU 5795 A Simple Nim(简单Nim)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  8. HDU 3533 Escape(大逃亡)

    HDU 3533 Escape(大逃亡) /K (Java/Others)   Problem Description - 题目描述 The students of the HEU are maneu ...

  9. HDU 1043 Eight(八数码)

    HDU 1043 Eight(八数码) 00 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)   Problem Descr ...

随机推荐

  1. Java Statement和PreparedStatement性能测试(转)

    本文转载自http://blog.csdn.net/liubo5005/article/details/7239935 先上代码: import java.sql.Connection; import ...

  2. bower install和cnpm install

    bower install :主要是安装前端的相关框架,如Boostarp,Angular等 cnpm install :主要是安装后端的,如express等

  3. rac安装oem

    [oracle@node1 ~]$ emca -config dbcontrol db -repos recreate -cluster STARTED EMCA at May 31, 2016 3: ...

  4. No DEFAULT or UI configuration directive found&excl;

    虚拟机安装OracleLinux出错: No DEFAULT or UI configuration directive found! 解决方法:我使用第一条就成功了 在报错信息后面的boot命令行输 ...

  5. 20155214&amp&semi;20155216 实验二:固件程序设计

    ---恢复内容开始--- 20155214&20155216 实验二:固件程序设计 实验内容及要求 实验二 固件程序设计-1-MDK 实验要求: 1.注意不经老师允许不准烧写自己修改的代码 2 ...

  6. &lbrack;LeetCode&rsqb; Transform to Chessboard 转为棋盘

    An N x N board contains only 0s and 1s. In each move, you can swap any 2 rows with each other, or an ...

  7. 设置placeholder无效解决办法

    一.设置placeholder的方法 placeholder属性用来设置控件内部的提示信息 <input type="text" placeholder="请输入用 ...

  8. 2&period;3&period;7synchronized代码块有volatile同步的功能

    关键字synchronized可以使多个线程访问同一个资源具有同步性,而且他还具有将线程工作内存中的私有变量与公共内存中的变量同步的功能. package com.cky.thread; /** * ...

  9. jmap dump文件压缩后失效

    最近线上出问题,于是用jmap -dump拿到dump文件,再linux压缩后拿到windows下无效,后来又直接拿了一个没有压缩的竟然可以用...坑啊!~

  10. ASP&period;NET MVC异常处理方案

    异常处理是每一个系统都必须要有的功能,尤其对于Web系统而言,简单.统一的异常处理模式尤为重要,当打算使用ASP.NET MVC来做项目时,第一个数据录入页面就遇到了这个问题. 在之前的ASP.NET ...