首页 > 其他 > 详细

HackerRank "Chocolate in Box" ?!

时间:2015-11-22 12:32:22      阅读:259      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!