Reprint Please specify source:http://blog.csdn.net/vmurder/article/details/42652745
In fact, I just feel that the original traffic is a bit more uncomfortable than unauthorized piracy 233 ...
Test instructions: N heap of stones, each can take some from a heap, you can also divide this heap into two non-empty heap, who can not operate who loses.
The solution: First we can play a SG function to solve the violence, but obviously this will be t.
But don't be afraid, we found a seemingly right pattern after the fight:
for all k >= 0, there is sg (4k+1) = 4k+1; sg (4k+2) = 4k+2; sg (4k+3) = 4k+4; sg (4k+4) = 4k+3.
Well, it can be solved quickly.
Code:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace Std;int Main () {int t,n,k,x;for (scanf ("%d", &t); t--;) {for (k=0,scanf ("%d", &n), n--;) {scanf ("%d", &x), if (x%4==0) k^= (x-1), else if (x%4==3) k^= (x+1); else k^=x;} if (k) puts ("Alice"); else puts ("Bob");}}
"HDU3032" "Lasker S Nim (a Nim game)" Nim or not nim? MULTI-SG game, play table