当前位置:
首页 >
HDU - 1907 John(尼姆博弈变形)
发布时间:2024/4/11
46
豆豆
生活随笔
收集整理的这篇文章主要介绍了
HDU - 1907 John(尼姆博弈变形)
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
题目链接:点击查看
题目大意:给出 n 堆石子,两个人轮流取,至少取一个,取到最后一个的人输
题目分析:尼姆博弈是取到最后一个的人获胜,这个题正好反着
一个很显然的奇异局势就是,每一堆的石子的个数都为 1 且有偶数堆石子,此时对应着异或和为 0
然后分两种情况讨论:
代码:
#include<iostream> #include<cstdio> #include<string> #include<ctime> #include<cmath> #include<cstring> #include<algorithm> #include<stack> #include<climits> #include<queue> #include<map> #include<set> #include<sstream> using namespace std;typedef long long LL;typedef unsigned long long ull;const int inf=0x3f3f3f3f;const int N=1e5+100;int main() { #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #endif // ios::sync_with_stdio(false);int w;cin>>w;while(w--){int n;scanf("%d",&n);int _xor=0;bool flag=false;for(int i=1;i<=n;i++){int num;scanf("%d",&num);_xor^=num;if(num>1)flag=true;}if(_xor&&flag||!flag&&!_xor)puts("John");elseputs("Brother");}return 0; }
总结
以上是生活随笔为你收集整理的HDU - 1907 John(尼姆博弈变形)的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: POJ - 1284 Primitive
- 下一篇: CodeForces - 1353D C