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
 
//第一道nim博弈题
// T异或为0 S异或为1
//必胜态:T0态,S1态,S2态必胜
//必败态:S0态,T2态必输
 
 
#include <iostream>

using namespace std;

int main()
{
int t,n;
int sum1,sum2,ans;
int a[];
cin>>t;
while(t--)
{
cin>>n;
sum1=;
sum2=;
ans=;
for(int i=;i<n;i++)
{
cin>>a[i];
ans=ans^a[i];
if(a[i]>=)
sum2++;//富裕堆
else
sum1++;//孤单堆
}
if((ans&&sum2)||(!ans&&!sum2))
cout<<"John"<<endl;
if((ans&&sum1%!=&&sum2==)||(!ans&&sum2>=))
cout<<"Brother"<<endl;
}
return ;
}
Problem Description
Let's consider m apples divided into n groups. Each group contains no more than 100 apples, arranged in a line. You can take any number of consecutive apples at one time.
For example "@@@" can be turned into "@@" or "@" or "@ @"(two piles). two people get apples one after another and the one who takes the last is 
the loser. Fra wants to know in which situations he can win by playing strategies (that is, no matter what action the rival takes, fra will win).
 
Input
You will be given several cases. Each test case begins with a single number n (1 <= n <= 100), followed by a line with n numbers, the number of apples in each pile. There is a blank line between cases.
 
Output
If a winning strategies can be found, print a single line with "Yes", otherwise print "No".
 
Sample Input
2
2 2
1
3
 
Sample Output
No
Yes

#include <iostream>

using namespace std;

int main()
{
int n,ans,sum1,sum2;
int a[];
while(cin>>n)
{
sum1=sum2=ans=;
for(int i=;i<n;i++)
{
cin>>a[i];
ans=ans^a[i];
if(a[i]>=)
sum2++;
else
sum1++;
}
if((ans&&sum2)||(!ans&&!sum2))
cout<<"Yes"<<endl;
if((ans&&sum1%!=&&sum2==)||(!ans&&sum2>=))
cout<<"No"<<endl;
}
return ;
}

hdu 1907 John&& hdu 2509 Be the Winner(基础nim博弈)的更多相关文章

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

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

  2. hdu2509Be the Winner(反nim博弈)

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

  3. hdu 1907 John (anti—Nim)

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

  4. HDU 1907 John nim博弈变形

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

  5. HDU 1907 John (Nim博弈)

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

  6. hdu 1907 John(anti nim)

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

  7. hdu 1907 John (尼姆博弈)

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

  8. hdu 1907 John

    很简单的博弈论问题!!(注意全是1时是特殊情况) 代码如下: #include<stdio.h> #include<iostream> using namespace std; ...

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

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

随机推荐

  1. 完美的拥抱GitHub

    Visual Studio 2012完美的拥抱GitHub   前言 一直以来都想使用Git来管理自己平时积累的小代码,就是除了工作之外的代码了.有时候自己搞个小代码,在公司写了,就要通过U盘或者网盘 ...

  2. ORACLE总结系列1--network文件夹里的admin的三个文件信息

    sqlnet.ora 作用类似于linux或者其他unix的 nsswitch.conf文件,通过这个文件来决定怎么样找一个连接中出现的连接字符串(connect descriptor) 假如sqln ...

  3. iOS基础 - 通知中心(NSNotificationCenter)

    通知中心(NSNotificationCenter) 每一个应用程序都有一个通知中心(NSNotificationCenter)实例,专门负责协助不同对象之间的消息通信 任何一个对象都可以向通知中心发 ...

  4. 解决Timer回调方法重复调用的问题

    如果Timer的回调方法的执行时间很长,计时器可能在上个回调方法还没有完成的时候再次触发,如果我们只是想让一个回调方法执行完后再执行下一个回调方法,可以这样: private static Timer ...

  5. Google Adsense(Google网站联盟)广告申请指南

    Google AdSense 是一种获取收入的快速简便的方法,适合于各种规模的网站发布商.它可以在网站的内容网页上展示相关性较高的 Google 广告,并且这些广告不会过分夸张醒目.由于所展示的广告同 ...

  6. xcode5向APP store上传应用的时候注意点

    最近我在向appstore 上传应用的时候遇到了各种问题,由于网上的一些教程都是很久以前写的了,现在发布网站有些改动,所以自己走了很多弯路,不多说了,自己记录下犯下的错误吧.我是按照这片博客操作的:点 ...

  7. 搭建一个完整的Java开发环境

    搭建一个完整的Java开发环境 作为一个Java程序员,配置一个java开发环境是必备的技能,今天给广大菜鸟初学者补上一课.环境的配置,大概就分三个1,JDK 2,Tomcat(或者其他的)3,ecl ...

  8. Visual Stuido 2010/2012 扩展:Quick Launcher,快速打开指定文件

    Visual Stuido 2010/2012 扩展:Quick Launcher,快速打开指定文件 Quick Launcher 是一个极其简单但实用的 Visual Studio 扩展,支持 Vi ...

  9. C语言的变量的内存分配

    今晚看了人家写的一个关于C语言内存分配的帖子,发现真是自己想找的,于是乎就收藏了... 先看一下两段代码: char* toStr() { char *s = "abcdefghijkl&q ...

  10. Java网络请求getInputStream异常

    今天调试网络请求部分时,当getInputStream失败时直接抛出异常.解决方法时在getInputStream之前获取ResponseCode if( connection.getResponse ...