XOR -> 0 is the key (make it even pair): http://www.cnblogs.com/lautsie/p/3908006.html
Something to learn about basic Game Theory: http://www.cdf.toronto.edu/~ajr/270/probsess/03/strategy.html
You can see, it is all about state(bit) toggling.
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { int n; cin >> n; vector<int> in(n); int initTaken = 0; for(int i = 0; i < n; i ++) { cin >> in[i]; initTaken ^= in[i]; } int cnt = 0; for(int i = 0; i < n; i ++) if (in[i] > (in[i]^initTaken)) // we can take this many out of it cnt ++; cout << cnt << endl; return 0; }
HackerRank "Chocolate in Box" ?!
原文:http://www.cnblogs.com/tonix/p/4985537.html