HDU - 1907 John(尼姆博弈变形)
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                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
