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 ...
随机推荐
- mvc4 membership, [Win32Exception (0x80004005): The system cannot find the file specified]
public class UsersContext : DbContext { public UsersContext() : base("conn1") //change the ...
- Unity给力插件之MegaFiers
这是一个关于网格变形的插件.其中有非常多的功能. 这是它的API地址:http://www.west-racing.com/mf/ 花了2天的时间实践并整理了其中绝大多数的功能,只有一些关于特殊格式的 ...
- Servlet的一些API使用介绍
final String rootPath = getServletConfig().getServletContext().getRealPath("/"); 获取项目运行的根 ...
- IronPython脚本调用C#dll示例
上篇Python脚本调用C#代码数据交互示例(hello world)介绍了与C#紧密结合的示例,这里还将提供一个与C#结合更紧密的示例,直接调用C#编写的DLL. 我们还是沿用了上篇文章的 ...
- 【UVA 1411】 Ants (KM)
Young naturalist Bill studies ants in school. His ants feed onplant-louses that live on apple trees. ...
- 李洪强iOS开发Swift篇---11_变量&常量&元组
李洪强iOS开发Swift篇---11_变量&常量&元组 说明: 1)终于要写一写swift了.其实早在14年就已经写了swift的部分博客,无奈时过境迁,此时早已不同往昔了.另外,对 ...
- [转贴]JAVA :RESTLET开发实例(一)基于JAX-RS的REST服务
RESTLET介绍 Restlet项目为“建立REST概念与Java类之间的映射”提供了一个轻量级而全面的框架.它可用于实现任何种类的REST式系统,而不仅仅是REST式Web服务. Restlet项 ...
- android java 堆栈的实现
android和java不提供堆栈的实现,只提供了list,vector,deque得存储结构,对于以前做面向过程语言的程序员来说,总觉得缺少了些什么: Stack.java文件: public cl ...
- [置顶] linux内核启动1-启动参数(启动参数的获取和处理,分析setup_arch)
最近公司要求调试一个内核,启动时有问题,所以就花了一点时间看看内核启动. 看的过程中总结了一点东西,希望可以帮助大家调试内核. 当我开始看的时候,第一件事是从网上搜集资料,不看不知道,一看吓一跳!牛人 ...
- 如何在windows系统自带命令查看硬件信息?
如何在windows系统自带命令查看硬件信息? 对于在windows下查看系统信息大家一定不陌生了,我现在说几个最常用的方法,对命令感兴趣的朋友看看,(给菜鸟看的,老手就不要笑话我了,大家都是从那个时 ...