码迷,mamicode.com
首页 > 其他好文 > 详细

HackerRank "Chocolate in Box" ?!

时间:2015-11-22 12:35:28      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

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

 

HackerRank "Chocolate in Box" ?!

标签:

原文地址:http://www.cnblogs.com/tonix/p/4985537.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!