The main topic: Anti-Nim game, that is, take the last one to lose
First State 1: Assuming that all of the heap is 1, then the heap number for even win, otherwise the initiator will be defeated
Then state 2: Assuming that there are two heaps of the same number and not 1, then the FLAC has the ability to control the field, namely:
If the initiator takes a pile, then he can choose to leave a pile of 1 or all to take, so that the two piles are finally only 1 or 0;
If the initiator will be a bunch of left one, then the hand can choose to have a bunch of left a starters hands or all take away, so that the two piles finally only 1 or 0 left;
If the initiator takes a bunch away. Then he can have a bunch of the same take-off part, and then ibid
Status 3: If Xor!=0 so that the first can take a part of xor=0 and then the same state 2 to win or the initiator will be defeated
※ In view of my excessive sand tea, the above content only has the reference value. Not be able to prove correctness, please correct me
So if all the heap is 1 xor==0 initiator win or the other will win
If there is a heap is not 1 xor==0 to win otherwise the initiator win
#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 Little John's game John game theory