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位置,每次至少走一步且不能超过他前面(下标小)的那个球,谁不能操作谁就输了 题解: ...
随机推荐
- JVM监测分析JConsole
一.基本操作 启动界面 1.JConsole是什么 从Java 5开始引入了JConsole.JConsole是一个内置Java性能分析器,可以从命令行或在GUI shell中运行.您可以轻松地使 ...
- linux下GPRS模块的应用程序
---------------------------------------------------------------------------------------------------- ...
- FL2440 rt3070模块station模式移植
---------------------------------------------------------------------------------------------------- ...
- [Python爬虫] 之二十:Selenium +phantomjs 利用 pyquery通过搜狗搜索引擎数据
一.介绍 本例子用Selenium +phantomjs 利用 pyquery通过搜狗搜索引擎数据()的资讯信息,输入给定关键字抓取资讯信息. 给定关键字:数字:融合:电视 抓取信息内如下: 1.资讯 ...
- Kubernetes概念介绍和v1版本部署过程
简介: k8s一个开源的,跨主机管理容器应用集群的编排系统,为应用提供了基础的部署.维护和扩缩容机制. 编排:跨Docker主机同一管理容器集群. 目的 简化开发和运维容器集群的工作. 让开发和运维能 ...
- vim删除文本文件中末行^M
^M字符的来历和作用:在DOS/Windows里,文本文件的换行符为\r\n,而在*nix系统里则为\n,所以DOS/Windows里编辑过的文本文件到了*nix里,每一行都多了个^M.所以^M只是一 ...
- Node.js meitulu图片批量下载爬虫1.06版
//====================================================== // https://www.meitulu.com图片批量下载Node.js爬虫1. ...
- 说说Linux文件权限那些事儿
文件全部权 显示文件的全部权 更改文件的全部权 文件的权限 改动文件的权限 用符号表示法改动 用数字表示法改动 使用umask指定默认的文件权限 參考文献 首先我们要知道Linux的标准文件权限和安全 ...
- AR路由器web界面每IP限速配置方法
一.做下载方向的限速:在 QOS>接口限速,选择“新建”“接口名称”选择内网接口“限速类型”选择IP限速(目的)“方向”选择流出“起始/目的ip”写内网的ip“类型”选择独占“承诺速率”为限速的 ...
- MATLAB 的通用命令
MATLAB 的通用命令 1.MATLAB 的标点符号及其特殊功能. 2.MATLAB 的键盘按键及其特殊功能. ↑或者Ctrl+p:调用上一次的命令 ↓或者Ctrl+n:调用下一行的命令 ←或者Ct ...