Alice and Bob are playing a strange game. The rules of the game are:
- Initially there are n piles.
- A pile is formed by some cells.
- Alice starts the game and they alternate turns.
- In each tern a player can pick any pile and divide it into two unequal piles.
- If a player cannot do so, he/she loses the game.
Now you are given the number of cells in each of the piles, you have to find the winner of the game if both of them play optimally.
Input
Input starts with an integer T (≤ 1000), denoting the number of test cases.
Each case starts with a line containing an integer n (1 ≤ n ≤ 100). The next line contains n integers, where the ith integer denotes the number of cells in the ith pile. You can assume that the number of cells in each pile is between 1 and 10000.
Output
For each case, print the case number and 'Alice' or 'Bob' depending on the winner of the game.
Sample Input
3
1
4
3
1 2 3
1
7
Sample Output
Case 1: Bob
Case 2: Alice
Case 3: Bob
题解:对于每一个数下一个拆分为 (1,n-1),(2,n-2) ... 个
SG函数推到即可;
参考代码:
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn=10010; 5 int T,n,SG[maxn],x,ans,vis[maxn]; 6 void getSG(int n) 7 { 8 for(int i=1;i<=n;++i) 9 { 10 memset(vis,0,sizeof vis); 11 for(int j=1;j*2<i;++j) if(i!=j*2) vis[SG[j]^SG[i-j]]=1; 12 for(int j=0;j<maxn;++j){ if(!vis[j]) { SG[i]=j;break; } } 13 } 14 } 15 int main() 16 { 17 scanf("%d",&T); 18 getSG(maxn); 19 for(int cas=1;cas<=T;++cas) 20 { 21 scanf("%d",&n);ans=0; 22 for(int i=1;i<=n;++i) 23 { 24 scanf("%d",&x); 25 ans^=SG[x]; 26 } 27 if(ans) printf("Case %d: Alice ",cas); 28 else printf("Case %d: Bob ",cas); 29 } 30 return 0; 31 }