Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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;
}
View Code

 

posted on 2015-11-22 11:56  Tonix  阅读(188)  评论(0编辑  收藏  举报