您的位置:首页 > 其它

***qwb has a lot of Coins nim博弈

2017-06-04 23:02 267 查看

Description

qwb has a lot of coins. One day, he decides to play a game with his friend using these coins. He first puts some of his coins into M piles, each of which is composed of Ni (1<=i<=M) coins. Then, the two players play the coin game in turns. Every step, one can remove one or more coins from only one pile. The winner is the one who removes the last coin.

Then comes the question: How many different ways the first player can do that will ensure him win the game?

Input

Input contains multiple test cases till the end of file. Each test case starts with a number M (1 <= M<= 1000) meaning the number of piles. The next line contains M integers Ni (1 <= Ni <= 1e9, 1 <= i<= M) indicating the number of coins in pile i.

Output

For each case, put the method count in one line.

If the first player can win the game, the method count is the number of different ways that he can do to ensure him win the game, otherwise zero.

Sample Input

3

1 2 3

1

1

Sample Output

0

1

Hint

题意

先手赢(捡完coin)输出赢得方案数

后手赢 输出0

题解:

nim博弈

方案数 当前堆异或总异或x 即除去这个堆的博弈结果

AC代码

#include <cstdio>

int main(){
int n;
int ar[1005];
while (~scanf("%d",&n)){
int x = 0;
int ans = 0;
for (int i = 0; i < n; ++i){
scanf("%d",&ar[i]);
x^=ar[i];
}if (x!=0){
for (int i = 0; i < n; ++i){
int y = x^ar[i];
if (ar[i] >= y) ans++;
}
}
printf("%d\n",ans);

}
return 0;
}


*方案数求法???
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: