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
题意
nim游戏 求胜利的方法次数
题解:
由于nim游戏必胜态为非零 当确定之后就可以++了 所以水题一枚 判断下第一次或与值就可以了
AC代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
typedef long long LL;
int arr[N];
int main()
{
int n;
while(~scanf("%d",&n)) {
int ans = 0;
for(int i = 0;i < n; i++) {
scanf("%d",&arr[i]);
ans ^= arr[i];
}
int k = 0;
int res;
if(ans) {
for(int i = 0;i < n; i++) {
res = arr[i]^ans;
if(res <= arr[i]) k++;
}
}
if(ans) printf("%d\n",k);
else printf("0\n");
}
return 0;
}