Misere Nim(LightOJ-1253)

题面

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 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].

输出

For each case, print the case number and ‘Alice’ if Alice wins otherwise print ‘Bob’.

样例输入

13
24
32 3 4 5
45
51 1 2 4 10
61
71

样例输出

1Case 1: Bob
2Case 2: Alice
3Case 3: Bob

提示

思路

Anti-Nim博弈,可以参见【题解】POJ-3480 John

代码

 1using namespace std;
 2
 3int main()
 4{
 5    int T; scanf("%d", &T);
 6    for(int cs=1; cs<=T; cs++)
 7    {
 8        int n; scanf("%d", &n);
 9
10        int nim=0, anti=0;
11        for(int i=0; i<n; i++){
12            int x; scanf("%d", &x);
13            if(x>1) anti = 1;
14            nim ^=x;
15        }
16        printf("Case %d: ", cs);
17        if((!nim&&!anti) || (nim&&anti)){
18            printf("Alice\n");
19        }else{
20            printf("Bob\n");
21        }
22    }
23    return 0;
24}