HDUOJ----John
John
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 2095 Accepted Submission(s): 1133
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
http://acm.hdu.edu.cn/showproblem.php?pid=1907
Recommend
lcy
简单的nim博弈.....(但是要注意全部为1的情况)....那是就不是nim博弈啦!!
代码:我想说的是,要把名字看清楚,开始将Johe---打错了...打成jone ,哎!!,尼玛,那叫一个错呀!!
//http://acm.hdu.edu.cn/showproblem.php?pid=1907
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
int main()
{
int t,n,i,x;
bool flag ;
cin>>t;
while(t--)
{
scanf("%d",&n);
vector<int>num(n+1);
x=0,flag=false;
for(i=0;i<n;i++)
{
scanf("%d",&num[i]);
x^=num[i];
}
for(i=0;i<n;i++)
{
if(num[i]>1)
{
flag=true;
break;
}
}
if(flag)
{
if(x) puts("John");
else puts("Brother");
}
else
{
if(n&1)
puts("Brother"); //奇数 win
else
puts("John"); //偶数 win
}
}
return 0;
}
- Kafka剖析系列之高可用(下)
- 11 个简单的 Java 性能调优技巧
- NativeScript工作原理
- 如何合并Git 代码库中牛人的代码到自己的库
- Kafka剖析系列之Consumer解析
- android之View绘制
- 高性能JavaScript-JS脚本加载与执行对性能的影响
- CSS3伪类和伪元素的特性和区别
- Kafka剖析系列之Benchmark
- 初探React与D3的结合-或许是visualization的新突破?
- Redis 在Centos Linux 上的启动脚本
- 理解JavaScript的临时包装对象
- JavaScript实现私有属性
- 使用LRU算法缓存图片,android 3.0
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 03 . Shell数组和函数
- Shell百宝箱(后续会不断更新)
- 09 . Prometheus监控tomcat+jvm
- 09 . Kubernetes之pv、pvc及使用nfs网络存储应用
- 10 . Kubernetes之Configmap,Secret
- struts2(三)---使用EL表达式,显示Action中的数据
- 02 . 分布式存储之FastDFS 高可用集群部署
- 11 . KubernetesRBAC认证及ServiceAccount、Dashboard
- 12 . Kubernetes之Statefulset 和 Operator
- 01 . SaltStack部署配置及简单应用
- 02 . SaltStack高级用法(Python API)
- 小加载动画
- 日志收集工具简单对比
- [蓝桥杯][2013年第四届真题]幸运数
- 04 . Filebeat简介原理及配置文件和一些案例