qwb has a lot of Coins

原题:qwb has a lot of Coins

原题大意

qwb有很多硬币,他把这些硬币分成m堆,每堆有ni个硬币,比赛规则是这样的,参赛者有两个人,每次可以移走任意一堆的任意数量的硬币(大于等于1),两人交替移动,谁不能移动谁输。问对手先移动,如果qwb能赢则输出赢的方式有几种,否则输出0。

算法分析

nim博弈

http://www.cnblogs.com/exponent/articles/2141477.html

程序代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
int n,a[1500];
int main(){
    while(scanf("%d", &n) == 1){
        int x = 0;
        for(int i = 0 ; i< n; i++)
        {
            scanf("%d", &a[i]);
            x^=a[i];
        }
        int ans = 0;
        if(x!=0){
            for(int i = 0; i < n; i++){
                int y = x^a[i];
                if(a[i] >= y) ans++;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}