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. 一个小团队TDD游戏及实践

    介绍的这个游戏是自己根据目前带的团队的实际情况来制定的, 在游戏实践过程中,收到了较好的效果,故打算把这个游戏分享出来,一是分享一下实践,而是集思广益,不断完善,更好的利用游戏来锻炼队伍.下面就将游戏 ...

  2. 手机APP下单支付序列图

    今天安装了Visio,学习了下如何使用,画了一下公司现在项目的下单支付序列图,话就不多说了,直接上图,处女作,欢迎指正!

  3. silverlight中datagrid数据到处excel

    首先新建一个DataGrdiExtensions类,代码为: public static class DataGridExtensions { /// <summary> /// 导出dg ...

  4. Azure的两种关系型数据库服务:SQL Azure与SQL Server VM的不同

    Azure的两种关系型数据库服务:SQL Azure与SQL Server VM的不同 <Windows Azure Platform 系列文章目录> 如果熟悉Windows Azure平 ...

  5. Jquery文本框值改变事件(支持火狐、ie)

    Jquery值改变事件支持火狐和ie浏览器,并且测试通过,绑定后台代码可以做成autocomplete控件. 具体代码列举如下: $(document).ready(function () { $(& ...

  6. 基于“泵”的TCP通讯(接上篇)

    基于“泵”的TCP通讯(接上篇) 上一篇博客中说了基于“泵”的UDP通讯,附上了一个Demo,模拟飞鸽传书的功能,功能不太完善,主要是为了说明“泵”在编程中的应用.本篇文章我再附上一个关于TCP通讯的 ...

  7. 什么时候用spring

    论公司spring的滥用   这个公司每个项目用不同的一套开发框架,实在忍不住拿一个出来说说事.

  8. 淘宝ued - 前端智勇大闯关(第三季)答案(更新)

    淘宝ued - 前端智勇大闯关(第三季)答案(更新) 下午在微博上看到了淘宝智勇大闯关第三季的信息,感觉挺有意思的,于是就尝试做了下.附上题目地址: http://ued.campus.alibaba ...

  9. 黑马程序员:Java基础总结----正则表达式

    黑马程序员:Java基础总结 正则表达式   ASP.Net+Android+IO开发 . .Net培训 .期待与您交流! 正则表达式 import  java.util.regex.*; 符合一定规 ...

  10. 当你在试衣间试衣服,请你务必想起wait()与notify()

    在学习多线程的时候,你无法逃避sleep.wait.notify.notifyAll的关键字,我们肯定是对sleep用的最多,即使你写个Demo也要经常用到Thread.sleep(xxx)模拟等待的 ...