题目
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并且ans=0.
第二种是不是全部的堆是1,并且ans!=0,其余的情况都是先手输!
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <string.h>
#include <string>
typedef long long ll;
#define INF 0x3f3f3f3f
using namespace std;
ll x;
int main() {
int t, num, ans, k;
int casenum = 0;
cin >> t;
while (t--){
num = 0;
ans = 0;
cin >> k;
while(k--){
cin >> x;
if (x >= 2) num++;
ans ^= x;
}
if ((ans != 0 && num != 0) || (ans == 0 && num == 0)) cout << "Case " << ++casenum << ": Alice" << endl;
else cout << "Case " << ++casenum << ": Bob" << endl;
}
return 0;
}