Title Address: HDU 1850
This game theory is different or this place feels really around, think about it, and finally give it clear. Summarize what you didn't understand before:
1: In the current operation, as long as you can achieve a certain must fail, then this point must be a winning state, because to win, will definitely choose the operation of the failure state.
2: Only when all values of the XOR value of 0 is a must, so say for the N heap of Nim game, the first step of the operation for each heap can only have at most one to form a must-fail state. The current heap is also unique because the XOR value of the other (n-1) heap is unique.
3: For each heap, as long as a number can be left, so that the number and the other (n-1) heap of the XOR value of 0, then this is a winning state. So as long as the value of the heap is greater than the number that can make it a must-lose state, it can form a scheme.
Having understood the above points, the problem is very simple. Just make a judgment on each pile.
The code is as follows:
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include < stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #include <map> #include < Set> #include <algorithm>using namespace Std;int a[200];int main () { int n, sum, x, I, tot; while (scanf ("%d", &n)!=eof&&n) { sum=0; tot=0; for (i=0;i<n;i++) { scanf ("%d", &a[i]); Sum^=a[i]; } if (sum==0) { puts ("0"); Continue; } for (i=0;i<n;i++) { x=a[i]^sum; if (X<a[i]) tot++; } printf ("%d\n", tot); } return 0;}
HDU 1850 Being A good boy in Spring Festival (NIM game)