Anti-nim game, that is, take the last person to lose
First State 1: If all the heap is 1, the number of heap is equal to that of the first hand. Otherwise, the first hand is defeated.
Then state 2: If the number of two heaps is the same but not 1, the latter has the field control capability, that is:
If the first hand takes a heap, the latter hand can choose to leave one or all of the other stacks, so that only one or 0 of the two stacks are left;
If one heap is left by the first hand, the latter can choose to leave another heap for the first hand to take or all, so that only one or zero heap is left;
If the first hand takes a part of the heap, the later hand can take the same part of the heap, and then
Status 3: If XOR! If it is set to 0, you can take a portion of the first hand and set XOR to 0. Then, in the same status, the first hand wins. Otherwise, the first hand loses.
※In view of the fact that I am too fond of tea, the above content only has reference value and cannot prove its correctness. please correct me.
So if all the heap is 1 XOR = 0, the first hand will win, or the second hand will win.
If a heap is not 1 XOR = 0, the first hand wins. Otherwise, the first hand wins.
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int n;bool Calculate(){int i,x,xor_sum=0;bool flag=1;cin>>n;for(i=1;i<=n;i++){scanf("%d",&x);if(x^1) flag=0;xor_sum^=x;}if(flag)return !xor_sum;elsereturn xor_sum;}int main(){int T,i;for(cin>>T;T;T--){if( Calculate() )puts("John");elseputs("Brother");}}
Bzoj 1022 shoi2008 John's game John Game Theory