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 一年在外 父母时刻牵挂春节回家 你能做几天好孩子吗寒假里 ...
随机推荐
- Objective-C Composite Objects
We can create subclass within a class cluster that defines a class that embeds within it an object. ...
- matlab均方根误差
Matlab均方根误差的计算 http://blog.sina.com.cn/s/blog_6210f654010308kv.html
- 如何使用KeyChain保存和获取UDID
本文是iOS7系列文章第一篇文章,主要介绍使用KeyChain保存和获取APP数据,解决iOS7上获取不变UDID的问题.并给出一个获取UDID的工具类,使用方便,只需要替换两个地方即可. 一.iOS ...
- Highcharts在IE8中不能一次性正常显示的一种解决办法
由于客户要求必须在IE浏览器下兼容图表,故选用了兼容性较好的Highcharts.另外说一句,博主尝试过ichartjs.ECharts.YUI,兼容性都没有Highcharts给力(所有的兼容性问题 ...
- 基于 Azure IaaS 搭建企业官网的规划和实践
本课程主要介绍了基于 Azure IaaS 搭建企业官网的案例分析和实践,实践讲解如何使用 Azure 门户创建虚拟机, 创建虚拟网络, 创建存储账户等. 具体包括项目背景介绍, 项目架构, 准备和实 ...
- perl在linux下通过date获取当前时间
perl处理文件的时候最好添加上 处理的时间戳,获取系统的时间又多种方法,但是反引号是最原始的,不需要其他外界条件和lib的支持. my $now = `date "+%F %T" ...
- 如何启动Intel VT-x
如何启动Intel VT-x 5 在64bit win7系统下安装了Vmware10,然后安装64位的UbuntuKylin 14.04,想要打开UbuntuKylin,弹出如下对话框: 请问该如何启 ...
- Webpack2 视频教程
原文发表于我的技术博客 这是我免费发布的高质量超清「Webpack 2 视频教程」.Webpack 作为目前前端开发必备的框架,Webpack 发布了 2.0 版本,此视频就是基于 2.0 的版本 ...
- 第1节 flume:13、14、更多flume案例一,通过拦截器实现不同类型的数据区分
1.6.flume案例一 1. 案例场景 A.B两台日志服务机器实时生产日志主要类型为access.log.nginx.log.web.log 现在要求: 把A.B 机器中的access.log.ng ...
- (1)JSTL的13个core标签库
标准标签库JSTL的全名为:Java Server Pages Standard Tag Library. (jsp standard tag library) JSTL主要提供了5大类标签库: ...