BZOJ1022 [SHOI2008]小约翰的游戏John
2016-09-14 19:08
330 查看
Description
小约翰经常和他的哥哥玩一个非常有趣的游戏:桌子上有n堆石子,小约翰和他的哥哥轮流取石子,每个人取的时候,可以随意选择一堆石子,在这堆石子中取走任意多的石子,但不能一粒石子也不取,我们规定取到最后一
粒石子的人算输。小约翰相当固执,他坚持认为先取的人有很大的优势,所以他总是先取石子,而他的哥哥就聪明
多了,他从来没有在游戏中犯过错误。小约翰一怒之前请你来做他的参谋。自然,你应该先写一个程序,预测一下
谁将获得游戏的胜利。
Input
本题的输入由多组数据组成第一行包括一个整数T,表示输入总共有T组数据(T≤500)。每组数据的第一行包括一个整数N(N≤50),表示共有N堆石子,接下来有N个不超过5000的整数,分别表示每堆石子的数目。
Output
每组数据的输出占一行,每行输出一个单词。如果约翰能赢得比赛,则输出“John”,否则输出“Brother”,请注意单词的大小写。
Sample Input
23
3 5 1
1
1
Sample Output
JohnBrother
HINT
Source
Seerc2007正解:博弈论
解题报告:
博弈论裸题,贾志豪的论文里面已经讲了这个模型,不再赘述。
只有在 不全为1且SG不为0或者全为1且SG为0 的情况下才会有先手必胜(即会让对方取到最后一个)。
//It is made by jump~ #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <cmath> #include <algorithm> #include <ctime> #include <vector> #include <queue> #include <map> #include <set> using namespace std; typedef long long LL; int n,x,SG; bool flag; inline int getint() { int w=0,q=0; char c=getchar(); while((c<'0' || c>'9') && c!='-') c=getchar(); if(c=='-') q=1,c=getchar(); while (c>='0' && c<='9') w=w*10+c-'0', c=getchar(); return q ? -w : w; } inline void work(){ int T=getint(); while(T--) { n=getint(); flag=false; SG=0; for(int i=1;i<=n;i++) { x=getint(); SG^=x; if(x>1) flag=1; } if((flag==false&&SG==0) || (flag==true&&SG>0)) printf("John"); else printf("Brother"); printf("\n"); } } int main() { work(); return 0; }
相关文章推荐
- bzoj1022 [SHOI2008]小约翰的游戏John
- 12.7 bzoj1022 [SHOI2008]小约翰的游戏John
- bzoj1022 [SHOI2008]小约翰的游戏John
- BZOJ 1022 SHOI2008 小约翰的游戏John 博弈论
- BZOJ 1022: [SHOI2008]小约翰的游戏John【anti-SG】
- BZOJ 1022 [SHOI2008]小约翰的游戏John 题解与分析
- bzoj 1022: [SHOI2008]小约翰的游戏John(反nim游戏)
- [BZOJ1022][SHOI2008]小约翰的游戏John(博弈Anti-Nim游戏)
- 【BZOJ 1022】 [SHOI2008]小约翰的游戏John
- [Anti-Nim Anti-SG SJ定理] BZOJ 1022 [SHOI2008]小约翰的游戏John
- BZOJ 1022 SHOI2008 小约翰的游戏John 博弈论
- [博弈] BZOJ1022: [SHOI2008]小约翰的游戏John
- BZOJ 1022 [SHOI2008]小约翰的游戏John
- BZOJ1022 [SHOI2008]小约翰的游戏John 【博弈论】
- 【BZOJ】1022: [SHOI2008]小约翰的游戏John(博弈论)
- 【BZOJ1022】【SHOI2008】小约翰的游戏John
- BZOJ 1022 [SHOI2008]小约翰的游戏John
- BZOJ1022 [SHOI2008]小约翰的游戏John 【博弈论】
- 【bzoj1022】【SHOI2008】【小约翰的游戏John】【博弈论】
- BZOJ 1022 [SHOI2008]小约翰的游戏John