Alice and Bob are playing game of Misère Nim. Misère Nim is a game playing on k piles of stones, each pile containing one or more stones. The players alternate turns and in each turn a player can select one of the piles and can remove as many stones from that pile unless the pile is empty. In each turn a player must remove at least one stone from any pile. Alice starts first. The player who removes the last stone loses the game.
Input
Input starts with an integer T (≤ 200), denoting the number of test cases.
Each case starts with a line containing an integer k (1 ≤ k ≤ 100). The next line contains k space separated integers denoting the number of stones in each pile. The number of stones in a pile lies in the range [1, 109].
Output
For each case, print the case number and Alice if Alice wins otherwise print Bob.
Sample Input
3
4
2 3 4 5
5
1 1 2 4 10
1
1
Sample Output
Case 1: Bob
Case 2: Alice
Case 3: Bob
题意:给你若干堆石子,每次可以从任意一堆中挑选出来任意个,取最后一枚石子的人输。
大致还是尼姆博弈的模板,谁面临平衡状态谁输。
需要特判一种情况:当每一堆石子的个数全部都为1的时候,这个时候只能每次拿一个,根据1的奇偶性进行判断。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
int t,k=1,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int f=0;
int x,sum=0;
for(int i=0;i<n;i++)
{
scanf("%d",&x);
if(x!=1)
f=1;
sum^=x;
}
printf("Case %d: ",k++);
if(f==0)
{
if(n&1)
printf("Bob\n");
else
printf("Alice\n");
}
else
{
if(sum)
printf("Alice\n");
else
printf("Bob\n");
}
}
return 0;
}