POJ 3480 & HDU 1907 John(尼姆博弈变形)
题目链接:
id=3480
HDU:http://acm.hdu.edu.cn/showproblem.php?
pid=1907
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
PS:
尼姆博弈变形!
代码例如以下:
#include <cstdio>
#define maxn 5017
int main()
{
int t;
int a[maxn];
int n, s, k;
scanf("%d",&t);
while(t--)
{
s = 0, k = 0;
scanf("%d",&n);
for(int i = 0; i < n; i++)
{
scanf("%d",&a[i]);
if(a[i] > 1)
k++;
s = s^a[i];
}
if(k == 0)//全为1
{
if(n%2 == 0)//偶数堆
printf("John\n");
else
printf("Brother\n");
}
else
{
if(s)
printf("John\n");
else
printf("Brother\n");
}
}
return 0;
}
POJ 3480 & HDU 1907 John(尼姆博弈变形)的更多相关文章
- hdu 1907 John (尼姆博弈)
John Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submis ...
- hdu 1907 (尼姆博弈)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1907 Problem Description Little John is playing very ...
- hdu 1849 (尼姆博弈)
http://acm.hdu.edu.cn/showproblem.php? pid=1849 简单的尼姆博弈: 代码例如以下: #include <iostream> #include ...
- HDU 1907 John (Nim博弈)
John Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submis ...
- John 尼姆博弈
John Little John is playing very funny game with his younger brother. There is one big box filled wi ...
- HDU 1907:John(尼姆博弈变形)
John Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submi ...
- HDU - 1907 John 反Nimm博弈
思路: 注意与Nimm博弈的区别,谁拿完谁输! 先手必胜的条件: 1. 每一个小游戏都只剩一个石子了,且SG = 0. 2. 至少有一堆石子数大于1,且SG不等于0 证明:1. 你和对手都只有一种选 ...
- hdu 1907 尼姆博弈
John Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submis ...
- hdu 4315 Climbing the Hill && poj 1704 Georgia and Bob阶梯博弈--尼姆博弈
参考博客 先讲一下Georgia and Bob: 题意: 给你一排球的位置(全部在x轴上操作),你要把他们都移动到0位置,每次至少走一步且不能超过他前面(下标小)的那个球,谁不能操作谁就输了 题解: ...
随机推荐
- rundll32.exe的相关使用语句
命令列: rundll32.exe shell32.dll,Control_RunDLL 功能: 显示控制面板 命令列: rundll32.exe shell32.dll,Control_RunDLL ...
- DEDECMS爆严重安全漏洞
简要描述: 众所周知,因使用简单.客户群多,织梦CMS一直被爆出许多漏洞.“DEDECMS爆严重安全漏洞,近期官方会发布相关补丁,望大家及时关注补丁动态.” 详细说明: http://www.xx.c ...
- Java开发中的23种设计模式详解 【转】
创建型模式,共五种:工厂方法模式.抽象工厂模式.单例模式.建造者模式.原型模式. 行为型模式,共十一种:策略模式.模板方法模式.观察者模式.迭代子模式.责任链模式.命令模式.备忘录模式.状态模式.访问 ...
- edittext SearchView 失去焦点问题
edittext 默认自己主动获取焦点的 并且会出现小键盘非常烦人 <LinearLayout android:id="@+id/focus" ...
- 使用JavaScript和Canvas实现下雪动画效果
该下雪动画效果使用了HTML5中Canvas画布实现,其中涉及了物理学中曲线运动的相关知识与运算. index.html <!DOCTYPE html> <html lang=&qu ...
- 【FAQ】Ubuntu环境下ant编译android代码问题
在Ubuntu14.04环境下,编译android程序时候,运行ant debug的时候出现如下异常:
- Taobao OpenERP Connector 简要说明
Taobao OpenERP Connector 项目托管地址:https://github.com/buke/openerp-taobao 作者: wangbuke@gmail.com 功能: 1. ...
- css3组件实战--绚丽效果篇
代码地址如下:http://www.demodashi.com/demo/11656.html 一.3D风景动态骰子 在线演示 1.css3D.动画基础知识预备 2.创建一个3D场景 先放置一个.bo ...
- 04-1下载Win系统(装机助理)
下载Win系统(装机助理): http://www.zhuangjizhuli.com/upan.html http://www.krlxx.com/64win7.html 选择你需要安装的系统: 以 ...
- Go环境IDE安装配置
终于配好了自己的Go环境,每天可以来一点积累了. MAC安装配置过程参考了如下几个博文~谢谢 Intellij安装配置: http://blog.csdn.net/fenglailea/article ...