hdu 1907 尼姆博弈
John
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 3745 Accepted Submission(s): 2116
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.
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
T lines each of them containing information about game winner. Print
“John” if John will win the game or “Brother” in other case.
3
3 5 1
1
1
Brother
#include<stdio.h>
#include<string.h>
#include<math.h>
int a[]; int main(){
int t;
scanf("%d",&t);
int n;
while(t--){
scanf("%d",&n);
bool flag=true;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]!=)
flag=false;
}
int ans=a[];
for(int i=;i<=n;i++)
ans=ans^a[i]; if(flag){
if(n%)
printf("Brother\n");
else
printf("John\n"); }
else{
if(ans)
printf("John\n");
else
printf("Brother\n");
} }
return ;
}
hdu 1907 尼姆博弈的更多相关文章
- hdu 1850(尼姆博弈)
Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32 ...
- hdu 1907 (尼姆博弈)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1907 Problem Description Little John is playing very ...
- POJ 3480 & HDU 1907 John(尼姆博弈变形)
题目链接: PKU:http://poj.org/problem? id=3480 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=1907 Descri ...
- hdu 1849 (尼姆博弈)
http://acm.hdu.edu.cn/showproblem.php? pid=1849 简单的尼姆博弈: 代码例如以下: #include <iostream> #include ...
- HDU.1850 being a good boy in spring festival (博弈论 尼姆博弈)
HDU.1850 Being a Good Boy in Spring Festival (博弈论 尼姆博弈) 题意分析 简单的nim 博弈 博弈论快速入门 代码总览 #include <bit ...
- hdu 1849(Rabbit and Grass) 尼姆博弈
Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4315 Climbing the Hill (阶梯博弈转尼姆博弈)
Climbing the Hill Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Su ...
- HDU 2176 取(m堆)石子游戏 尼姆博弈
题目思路: 对于尼姆博弈我们知道:op=a[1]^a[2]--a[n],若op==0先手必败 一个简单的数学公式:若op=a^b 那么:op^b=a: 对于第i堆a[i],op^a[i]的值代表其余各 ...
- 题解报告:hdu 1850 Being a Good Boy in Spring Festival(尼姆博弈)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1850 Problem Description 一年在外 父母时刻牵挂春节回家 你能做几天好孩子吗寒假里 ...
随机推荐
- Windows下Apache+PHP+MySQL开发环境的搭建(WAMP)
准备工作: 1.下载apache服务器安装包,官网http://www.apache.org/,下载地址:http://httpd.apache.org/download.cgi 2.下载MySQL, ...
- 解决部分浏览器不能显示itext生成的PDF文件文本域内容问题
利用Itext可以实现pdf的高效动态生成,但在实践过程中遇到了一个问题: 即itext利用map中的值设置到pdf模板上建立的文本域中时:能成功生成,但是在部分浏览器上(360,QQ,等浏览器)无法 ...
- 洛谷 P1926 小书童——刷题大军
题目背景 数学是火,点亮物理的灯:物理是灯,照亮化学的路:化学是路,通向生物的坑:生物是坑,埋葬学理的人. 文言是火,点亮历史宫灯:历史是灯,照亮社会之路:社会是路,通向哲学大坑:哲学是坑,埋葬文科生 ...
- 洛谷 P1009 阶乘之和
题目描述 用高精度计算出S=1!+2!+3!+…+n!(n≤50) 其中“!”表示阶乘,例如:5!=5*4*3*2*1. 输入输出格式 输入格式: 一个正整数N. 输出格式: 一个正整数S,表示计算结 ...
- 洛谷 P1276 校门外的树(增强版)
题目描述 校门外马路上本来从编号0到L,每一编号的位置都有1棵树.有砍树者每次从编号A到B处连续砍掉每1棵树,就连树苗也不放过(记 0 A B ,含A和B):幸运的是还有植树者每次从编号C到D 中凡是 ...
- Caused by: java.lang.ClassNotFoundException: org.springframework.boot.system.JavaVersion
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.system.JavaVersion Invalid pro ...
- afnetworking NSCocoaErrorDomain Code=3840 解决
afnetworking json解析出错 解决方法1 AFURLResponseSerialization.m 258行修改 responseString = [responseString str ...
- build.sbt的定义格式
一个简单的build.sbt文件内容如下: name := "hello" // 项目名称 organization := "xxx.xxx.xxx" // 组 ...
- python基础一 day13 生成器
#生成器函数# def generator():# print(1)# return 'a'## ret = generator()# print(ret) #只要含有yield关键字的函数都是生成器 ...
- webpack之postcss集成
项目 为了 兼容各个浏览器,需要加各种 c3前缀,如果手动的加肯定 相对比较麻烦,但是现在有webpack,gulp之类的 工具可以自动给我们加上,可以说效率上加速不少.如果 配置中 做个happyp ...