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. HDU 1907 John nim博弈变形

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

  2. hdu 1907 John

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

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

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

  4. HDU - 1907 John 反Nimm博弈

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

  5. HDU 1907 Nim博弈变形

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

  6. HDU 2509 Nim博弈变形

    1.HDU 2509  2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...

  7. HDU 5754 Life Winner Bo 组合博弈

    Life Winner Bo Problem Description   Bo is a "Life Winner".He likes playing chessboard gam ...

  8. HDU 2509 Be the Winner nim博弈变形

    Be the Winner Problem Description   Let's consider m apples divided into n groups. Each group contai ...

  9. HDU 1907 (博弈) John

    参见上一篇博客,里面有分析和结论. #include <cstdio> int main() { int T; scanf("%d", &T); while(T ...

随机推荐

  1. php_zip 类

    <?php /** * Created by PhpStorm. * User: StarZhan * Date: 2016/5/24 * Time: 12:04 */class PHPZip{ ...

  2. C#连接SQLServer数据库基本实现

    (在这写下来,防止以后忘记) 在VS2012中新建一个Windows窗口应用程序,并在Form中放置DataGridView和Button两个控件,在Button的单击响应事件中连接数据库: priv ...

  3. 初步了解CPU

    了解CPU By JackKing_defier 首先说明一下,本文内容主要是简单说明CPU的大致原理,所需要的前提知识我会提出,但是由于篇幅我不会再详细讲解需要的其他基础知识.默认学过工科基础课. ...

  4. EMC学习之电磁辐射

    我们在接触新鲜事物的时候,通常习惯用自己熟悉的知识去解释自己不熟悉的事物.EMC知识更多的涉及到微波和射频,对于像我这种专注于信号完整性而 对EMC知识知之甚少的菜鸟来说,最初也只能用SI的一些基础知 ...

  5. PHP遍历、删除文件夹中的所有文件

    <?php header("Content-type:text/html;charset=utf-8"); /** * getDirFile 遍历文件夹中的所有文件 * @p ...

  6. C#知识点总结系列:C# 数据结构

    线性表(Linear List) 线性表是一个线性结构,它是一个含有n≥0个结点的有限序列,对于其中的结点,有且仅有一个开始结点没有前驱但有一个后继结点,有且仅有一个终端结点没有后继但有一个前驱结点, ...

  7. alias重启终端失效的问题

    如果使用命令 alias xx='xxxx' 那么登出以后,别名就会失效.下次登入的时候就不能用了. 为了保持别名可以把它写入.bashrc 在.bashrc的最后写入想要的别名,比如 alias z ...

  8. (转)无法将类型为“Microsoft.Office.Interop.Word.ApplicationClass”的 COM 对象强制转换为接口类型“Microsoft.Office.Interop.Word._Application”。此操作失败的原因是对 IID 为“{00020970-

    HRESULT:0x80030002 无法将类型为“Microsoft.Office.Interop.Word.ApplicationClass”的 COM 对象强制转换为接口类型“Microsoft ...

  9. sql server 2008 express 使用ip登陆 error:40 错误:2

    如图 更好的方法是将IPAll中的TCP端口设置为1433.

  10. TypeScript:类(Classes)

    返回TypeScript手册总目录 传统的Javascript关注的是函数(function)和基于原型(prototype-based)的继承作为构建可重复使用组件的基本方式,但是与更舒服地使用面向 ...