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. ASP.NET MVC应用程序使用axd格式文件

    ASP.NET MVC应用程序使用axd格式文件 axd格式文件,不管是在asp.net还是现在开发asp.net MVC应用程序,都是Insus.NET较喜欢使用的. 因为我们可以虚拟一个在应用程序 ...

  2. Effective C++(14) 在资源管理类中小心copying行为

    问题聚焦:     上一条款所告诉我们的智能指针,只适合与在堆中的资源,而并非所有资源都是在堆中的.     这时候,我们可能需要建立自己的资源管理类,那么建立自己的资源管理类时,需要注意什么呢?. ...

  3. c# 窗体最小化后截图实现

    我们知道,当我们需要对Control进行截图时,我们可以使用Control.DrawToBitmap()进行截图, 那么问题来了,当我们的窗体最小化了,我们还怎么截图呢? 当窗体最小化的时候,我们知道 ...

  4. float的深入剖析

    float的深入剖析   float是什么? float即为浮动,在html中的作用是使元素脱离正常的文档流并使其移动到其父元素的“最左边”或“最右边”.下面解释下这个定义中的几个名词的概念: 文档流 ...

  5. 玩下Javascript

    玩下Javascript 前言 好久没有更新博客了,也蛮少捣弄javascript,今儿看到一个题目,关于给你一个面板,你可以随意的在上面画矩形,可以移动和删除任意一个你创建的矩形,心血来潮搞着玩哈, ...

  6. python 爬虫总结【转】

    1.基本抓取网页 get方法 import urllib2 url = "http://www.baidu.com" response = urllib2.urlopen(url) ...

  7. 搜索广告与广告网络Demand技术-搜索广告

    搜索广告 搜索广告就是一个典型的Ad Network,但是搜索广告非常重要,它的收入非常高,所以它有其独特之处,复杂度也比展示广告要高.它与展示广告在点击率预测,检索部分差不多,它的特点:1. 用户定 ...

  8. gcc编译器优化给我们带来的麻烦???

    gcc编译器优化给我们带来的麻烦??? 今天看到一个很有趣的程序,如下: ? 1 2 3 4 5 6 7 8 9 int main() {     const int a = 1;     int * ...

  9. 跨平台C/C++集成开发环境-Code::Blocks-内置GCC

    Code::Blocks 是一个开放源码的全功能的跨平台C/C++集成开发环境. 相比于基于Delphi的Dev-C++共享C++IDE,Code::Blocks是开放源码软件.Code::Block ...

  10. Organic Solar Cells - Generations of Solar Cells

    Sunlight --> Electricity A. E. Becquerel, 1839 . He stated that we can get energy from sunlight. ...