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;
    ];
    cin>>t;
    while(t--)
    {
        cin>>n;
        sum1=;
        sum2=;
        ans=;
        ;i<n;i++)
        {
            cin>>a[i];
            ans=ans^a[i];
            )
            sum2++;//富裕堆
            else
            sum1++;//孤单堆
        }
        if((ans&&sum2)||(!ans&&!sum2))
        cout<<"John"<<endl;
        !=&&sum2==)||(!ans&&sum2>=))
        cout<<"Brother"<<endl;
    }
    ;
}
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;
    ];
    while(cin>>n)
    {
        sum1=sum2=ans=;
        ;i<n;i++)
        {
            cin>>a[i];
            ans=ans^a[i];
            )
            sum2++;
            else
            sum1++;
        }
        if((ans&&sum2)||(!ans&&!sum2))
        cout<<"Yes"<<endl;
        !=&&sum2==)||(!ans&&sum2>=))
        cout<<"No"<<endl;
    }
    ;
}

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

  1. POJ 3480 &amp;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

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

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

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

  8. HDU - 1907 John 反Nimm博弈

    思路: 注意与Nimm博弈的区别,谁拿完谁输! 先手必胜的条件: 1.  每一个小游戏都只剩一个石子了,且SG = 0. 2. 至少有一堆石子数大于1,且SG不等于0 证明:1. 你和对手都只有一种选 ...

  9. HDU 1907 Nim博弈变形

    1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...

随机推荐

  1. BOM以及定时器

    一.BOM 1.操作浏览器的一些方法 (浏览器对象模型) 2.window是is中的顶级变量,是一个全局的变量,所有人都可以访问到它,基本 的方法和属性 (document,alert,console ...

  2. html5吹牛扯淡篇,闲话内容。

    09年提出对媒体查询的草案,到今天的广泛运用,w3c带我们走进了个性化定制的殿堂.这些之所以会被认可会被写进世界级标准,因为他越来越适应广大用户的需求,需求就像一条锁链带动或者牵引整个互联网开发工作. ...

  3. OpenCV图像的缩放

    函数介绍:    1.cvResize 改变图像大小     void cvResize(const CvArr *src, CvArr *dst, int interpolation)    函数说 ...

  4. Android蓝牙连接以及数据接收发送

    1.加入权限 <uses-feature android:name="android.hardware.bluetooth_le" android:required=&quo ...

  5. Metasploitable 2系列教程:信息收集

    Metasploitable 2 系统是一个基于ubuntu 的系统.其设计的最初目的为安全工具测试和常见漏洞攻击演示.而在这篇关于 Metasploit 的教程中,我们将列举有关 Metasploi ...

  6. IE 兼容模式下不支持DIV CSS样式display:inline-block,解决

    样式改为: display: inline-block;*display: inline;zoom: 1; 就可以了

  7. LeetCode Populating Next Right Pointers in Each Node (技巧)

    题意: 给一棵满二叉树,要求将每层的节点从左到右用next指针连起来,层尾指向NULL即可. 思路: 可以递归也可以迭代.需要观察到next的左孩子恰好就是本节点的右孩子的next啦. (1)递归:这 ...

  8. PHP使用libevent实现高性能httpServer

    今天发现php也有一个libevent的扩展,安装后尝试下了一个webserver(httpserver), 发现性能还不错,逻辑很简单,每秒响应速度1800~4000次/s 代码如下 <?ph ...

  9. noip2007 树网的核

    P1099 树网的核 112通过 221提交 题目提供者该用户不存在 标签动态规划树形结构2007NOIp提高组 难度提高+/省选- 提交该题 讨论 题解 记录   题目描述 设T=(V, E, W) ...

  10. linux64下安装swftools

    在文档转换器中,需要在linux上安装swftools,经历了一番曲折过程终于安装成功.swftools安装包从http://www.swftools.org/download.html上面下载. 在 ...