Game theory
I cry ... Wrong idea, WA, 6 times? (There seems to be some wrong hand.) )
This is the first step to ask the NIM game to win strategies there are several.
At first I thought: all different or up to get ans, from each more than ans big heap take ans one, the answer is so cumulative ... wa!
Second: ans with each a[i] take &, if not 0 there is a scheme ... wa!
Third: ans with each a[i] take & if the result equals ans then there is a scheme ... wa!
Fourth time: ans with each a[i] take ^, if results <=a[i] There is a scheme ... ac!
Sigh ... Sure enough, "think Twice" and then ... (attached to an example, 25/17/22 these three heaps of XOR and is 30, scheme number is 3)
First we understand that XOR and ans>0 means that it is possible to take some stones to make xor and = 0, and of course to take the ANS stones from a heap to satisfy this condition, but it is not necessary to do so (as in the example above, the number of scenarios is 0). For a heap of Pebbles a[i], how many can we take to make XOR and =0? Of course it is ans^a[i], of course, if the heap itself is not so many is an illegal scheme, so the answer should be the idea of the four =
1 Source Code2Problem:2975user:sdfzyhy3 memory:400k time:0ms4language:g++result:accepted5 6 Source Code7 8 //POJ 29759#include <cstdio>Ten #defineF (i,j,n) for (int i=j;i<=n;++i) One intGetint () { A intv=0, sign=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') sign=-1; Ch=GetChar ();} - while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} the returnv*=Sign ; - } - Const intn=1e7+Ten; - /******************tamplate*********************/ + inta[1010]; - intMain () { + intN; A while(SCANF ("%d", &n)!=eof &&N) { at intans=0, s=0; -F (I,1, n) {a[i]=getint (); ans^=a[i];} - if(ANS) F (I,1, N)if((A[i]^ans) <=a[i]) s++; -printf"%d\n", s); - } - return 0; in}View Code
"POJ" "2975" Nim