Idea: If the total number of cards is different or the result of ans is 0, then must lose, output 0. Otherwise, you must give the other party a P-state, you can have all the poker heap to be checked, will ans^a[i] can be obtained in addition to a[i] Other poker number of different or results tmp, the purpose is to make TMP is 0, then certainly to take some cards from the a[i] heap, so that the remaining card number XOR or TMP is 0. What may happen (1) TMP is larger than a[i], then this is not the right solution. (2) Tmp=0, then take a[i] all away. (3) Tmp<a[i], then to take away a[i]-tmp card, leaving TMP Zhang, just different or the result is 0.
1#include <iostream>2#include <cstdio>3 using namespacestd;4 inta[101];5 intMain ()6 {7 //freopen ("Input.txt", "R", stdin);8 intN;9 while(cin>>n,n)Ten { One for(intI=0; i<n; i++) Ascanf"%d",&a[i]); - - intans=a[0], cnt=0; the for(intI=1; i<n; i++) -ans^=A[i]; - - if(!ans) cout<<"0"<<endl;//must lose + Else - { + for(intI=0; i<n; i++) A { at inttmp=ans^A[i]; - if(a[i]-tmp>=0) -cnt++; - } -cout<<cnt<<Endl; - } in } - return 0; to}
AC Code
HDU 1850 Being A good boy in spring Festival to be a good kid in Spring Festival (NIM game, micro-deformation)