对于任意一个 Anti-SG 游戏,如果我们规定当局面中所有的单一游戏的 SG 值为 0 时,游戏结束,则先手必胜当且仅当: 
(1)游戏的 SG 函数不为 0 且游戏中某个单一游戏的 SG 函数大于 1;
(2)游戏的 SG 函数为 0 且游戏中没有单一游戏的 SG 函数大于 1。

John

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 2233    Accepted Submission(s): 1200

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
 

Source
 

Recommend
lcy
 

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,XOR=0,a,k=0;
        scanf("%d",&n);
        while(n--)
        {
            scanf("%d",&a);
            XOR^=a;
            if(a>1) k++;
        }
        if((XOR==0&&k==0)||(XOR!=0&&k!=0))
            puts("John");
        else
            puts("Brother");
    }
    return 0;
}

* This source code was highlighted by YcdoiT. ( style: Codeblocks )

HDOJ 1907 John的更多相关文章

  1. hdu 1907 John (anti—Nim)

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

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

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

  3. HDU 1907 John nim博弈变形

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

  4. hdu 1907 John

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

  5. hdu 1907 John&& hdu 2509 Be the Winner(基础nim博弈)

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

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

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

  7. HDU - 1907 John 反Nimm博弈

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

  8. HDU 1907 John (Nim博弈)

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

  9. hdu 1907 John(anti nim)

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

随机推荐

  1. 表单验证之validform.js使用方法

    一.validform有什么用? 网页上有大量的input需要你进行验证的时候,如果是弹窗的话,需要不停地判断,如果为空,弹窗.如果不是数字,弹窗. 所以要将这么多验证交给一个js去验证. 二.我现在 ...

  2. Opencv step by step - 阈值化

    Opencv里面的阈值化做起来比较简单,只需要一个函数即可: /* Applies fixed-level threshold to grayscale image. This is a basic ...

  3. 关于UITextView / String的尺寸

    关于UITextView以及String的尺寸动态获取 iOS7开始,UITextView设置text后不会立即反映到contentSize属性,而是在父容器layoutSubviews时进行cont ...

  4. Windows Phone 开发——相机功能开发

    相机功能是手机区别于PC的一大功能,在做手机应用时,如果合理的利用了拍照功能,可能会给自己的应用增色很多.使用Windows Phone的相机功能,有两种方法,一种是使用PhotoCamera类来构建 ...

  5. 变量监控 指令 gt-wach

    index8.html <html><head> <title>变量监控指令 gt-watch</title> <script src=" ...

  6. ios上uiwebview的一些实用技巧

    前几个星期接到公司一个项目,要用webview在客户端上播视频,作为一个前端实习生,这种需求真是蛋疼……一不知webview是何方神圣,二不知咋调试…… 下面就是蛋疼的开始:  寻找调试工具:好,非w ...

  7. Bootstrap3.0学习第二十二轮(JavaScript插件——弹出框)

    详情请查看http://aehyok.com/Blog/Detail/28.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:ht ...

  8. 【探秘ES6】系列专栏(一):ES6简介

    摘要:新一代JavaScript标准,ES6即将发布.[探秘ES6]系列专栏将一一剖析ES6的诸多新特性,让Web开发者对此有清晰全面的了解.本文为系列的第一篇,带你了解ES6到底是什么以及有哪些令人 ...

  9. 【CodeForces 472A】Design Tutorial: Learn from Math

    题 题意:给你一个大于等于12的数,要你用两个合数表示出来.//合数指自然数中除了能被1和本身整除外,还能被其他的数整除(不包括0)的数. 分析:我们知道偶数除了2都是合数,给你一个偶数,你减去一个偶 ...

  10. Yii2 RBAC 用到的表

    Yii2 RBAC用到的四张auth表位于 vendor/yiisoft/yii2/rbac/migration文件夹里面,可以用migration生成 yii migrate --migration ...