John(博弈)
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 no te 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.
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.
Constrains:
1 <= T <= 474,
1 <= N <= 47,
1 <= Ai <= 4747
Sample Input
Sample Output
分析:博弈题,最后拿者输!
代码:
#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
int main()
{
//freopen("a.in","r",stdin);
//freopen("aa.out","w",stdout);
int t,n,i,in,cnt,ans;
while(scanf("%d",&t)!=EOF)
{
while(t--)
{
scanf("%d",&n);
cnt=0;ans=0;
for(i=0;i<n;i++)
{
scanf("%d",&in);
if(in==1)
cnt++;
ans^=in;
}
if(cnt==n)
{
printf("%s\n",(cnt%2!=1)?"John":"Brother");
continue;
}
if(ans!=0)
printf("John\n");
else
printf("Brother\n");
}
}
return 0;
}
John(博弈)的更多相关文章
- hdu1907 John 博弈
Little John is playing very funny game with his younger brother. There is one big box filled with M& ...
- POJ 3480 John [博弈之Nim 与 Anti-Nim]
Nim游戏:有n堆石子,每堆个数不一,两人依次捡石子,每次只能从一堆中至少捡一个.捡走最后一个石子胜. 先手胜负:将所有堆的石子数进行异或(xor),最后值为0则先手输,否则先手胜. ======== ...
- 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 ...
- HDU - 1907 John 反Nimm博弈
思路: 注意与Nimm博弈的区别,谁拿完谁输! 先手必胜的条件: 1. 每一个小游戏都只剩一个石子了,且SG = 0. 2. 至少有一堆石子数大于1,且SG不等于0 证明:1. 你和对手都只有一种选 ...
- POJ 3480 John(SJ定理博弈)题解
题意:n堆石头,拿走最后一块的输 思路:SJ定理:先手必胜当且仅当:(1)游戏的SG函数不为0且游戏中某个单一游戏的SG函数大于1:(2)游戏的SG函数为0且游戏中没有单一游戏的SG函数大于1. 参考 ...
- POJ 3480 & HDU 1907 John(尼姆博弈变形)
题目链接: PKU:http://poj.org/problem? id=3480 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=1907 Descri ...
- HDU 1907 John(博弈)
题目 参考了博客:http://blog.csdn.net/akof1314/article/details/4447709 //0 1 -2 //1 1 -1 //0 2 -1 //1 2 -1 / ...
- bzoj1022: [SHOI2008]小约翰的游戏John(博弈SG-nim游戏)
1022: [SHOI2008]小约翰的游戏John 题目:传送门 题目大意: 一道反nim游戏,即给出n堆石子,每次可以取完任意一堆或一堆中的若干个(至少取1),最后一个取的LOSE 题解: 一道 ...
- HDU 1907 John nim博弈变形
John Problem Description Little John is playing very funny game with his younger brother. There is ...
随机推荐
- LightOj_1364 Expected Cards
题目链接 题意: 一副牌, 每个花色13张牌,加上大小王,共54张. 遇到大小王可以代替其中某种花色. 给定C, D, H, S. 每次抽一张牌, 问抽到C张梅花, D张方块, H张红桃, S张黑桃所 ...
- IEEE会议排名(转载)
不知道谁整理的,我就下了个word.所以就标注不了,引用的哪的了. Rank 1: SIGCOMM: ACM Conf on Comm Architectures, Protocols & A ...
- MATLAB conv2卷积的实现
MATLAB conv2卷积的实现 二维卷积的算法原理比较简单,参考任意一本数字信号处理的书籍,而matlab的conv2函数的滤波有个形状参数,用下面的一张图很能说明问题: 这里给出一种最原始的实现 ...
- js 正则 非负整数
Javascript 正则表达式 非负整数 /** * 正则判断非负整数 */ function testnum(ob){ var reg=/^[0-9]+?$/; //如果正则需要判断非负整数并带2 ...
- 【BZOJ 1594】 [Usaco2008 Jan]猜数游戏 (二分+并查集)
1594: [Usaco2008 Jan]猜数游戏 Description 为了提高自己低得可怜的智商,奶牛们设计了一个新的猜数游戏,来锻炼她们的逻辑推理能力. 游戏开始前,一头指定的奶牛会在牛棚后面 ...
- 17.2.1 Replication Implementation Details 复制实现细节:
17.2 Replication Implementation 复制是基于master server 跟踪所有改变到他的数据库(更新,删除等等)在它的binary log. binary log 作为 ...
- 【HDOJ】3234 Exclusive-OR
并查集.对于对元素赋值操作,更改为I p n v.令val[n]=0(任何数与0异或仍为原值).考虑fa[x] = fx, fa[y] = fy.如果使得fa[fx] = fy, 那么val[fx] ...
- 利用if else咱们结婚吧
class Program { static void Main(string[] args) { while (true) ...
- index 辨别字符在字符串中的位置
namespace index{ class Program { static void Main(string[] args) { wh ...
- bzoj1878
像我这种蒟蒻这道题从在线算法思考基本毫无思路 但是发现题目中只涉及到询问而不涉及到修改,这类题目一般都是离线算法大概 考虑到这题为什么不能直接区间求值,因为区间中同色点会被重复计算(废话) 下面我们就 ...