HDU 1907 John
2016-04-20 17:45
369 查看
John
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 3954 Accepted Submission(s): 2244
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
Southeastern Europe 2007
题目大意:
john 和他的弟弟一起吃糖果,每次可以吃一堆中的至少一个,谁吃到最后一个谁输。输出谁必胜。
思路:
尼姆博奕的应用,关于尼姆博弈的证明,大家可以去kuangbin 哪里看一下,给你们贴出传送门,他那里还给出了一些基本的博弈题目供大家练习。
根据常识,如果开局都是孤单堆的话,那么谁先手,谁输。
根据定理,首先设 奇异局势 为 p 非 奇异局势 为 n 奇异局势是输局
那么,由定理的,p 可以由适当方式变为 n , 在 n 态下,任意做法都会使之变成 p 态。
那么,如果开局 是 p 态,先手输,否则先手胜。
感想:
这个题和南京理工那个校赛题目完全相同。啦啦啦~~很简单的对不对??
AC代码:
#include <iostream> using namespace std; int main() { int T,N,i,a[50],sum,k; cin>>T; while (T--) { cin>>N; k=0;//孤单堆的数量 sum=0; for (i=0;i<N;i++) { cin>>a[i]; sum^=a[i]; if (a[i]>1) { k=1;//如果不全部是孤单堆 } } if (k==0) //对于全是孤单堆的情况 { if (N%2==0) { cout<<"John"<<endl; } else { cout<<"Brother"<<endl; } } else { if (sum==0) //对于奇异局势的情况下 { cout<<"Brother"<<endl; } else //对于非奇异局势的情况下 { cout<<"John"<<endl; } } } return 0; }
相关文章推荐
- android多线程并发协调semaphore机制
- Spring HTTP Invoker使用介绍
- hiho 42 骨牌覆盖问题·二
- JSP杂项知识
- HTML DOM 属性
- 编译原理 词法分析
- JS性能优化笔记
- “并发用户数”、“系统用户数”和“同时在线用户数”的计算公式
- android开发 根据上传图片张数变换不同的布局
- iftop监控网卡,ip流量
- Sublime text 3 最新版 注册码 破解
- Configure,Makefile.am, Makefile.in, Makefile文件之间关系
- 取硬币问题
- c++11 线程池
- JDK容器与并发—并发
- LeetCode *** 92. Reverse Linked List II
- Linux Grub系统加密、破密、修复
- JDK容器与并发—Queue—LinkedBlockingQueue
- centos+zabbix(基于lamp)
- Android开发中,那些让你相见恨晚的方法、类或接口