Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 435 Accepted Submission(s): 288
Problem Description
Bob and Alice are playing a new game. There are n boxes which have been numbered from 1 to n. Each box is either empty or contains several cards. Bob and Alice move the cards in turn. In each turn the corresponding player should choose a non-empty box A and choose another box B that B<A && (A+B)%2=1 && (A+B)%3=0. Then, take an arbitrary number (but not zero) of cards from box A to box B. The last one who can do a legal move wins. Alice is the first player. Please predict who will win the game.
Input
The first line contains an integer T (T<=100) indicating the number of test cases. The first line of each test case contains an integer n (1<=n<=10000). The second line has n integers which will not be bigger than 100. The i-th integer indicates the number of cards in the i-th box.
Output
For each test case, print the case number and the winner's name in a single line. Follow the format of the sample output.
Sample Input
2 2 1 2 7 1 3 3 2 2 1 2
Sample Output
Case 1: Alice Case 2: Bob
题意:按照题目给定的A和B的要求,每次从A向B中转移任意数量的石子。最后不能操作的负。
思路:1.余0的箱子中的卡只能移到余3里,余3的箱子只能移到余0里。最终箱子编号为3;
2.余2的箱子中的卡只能移到余1里,余1的箱子只能移到余2里。最终箱子编号为1;
3.余4的箱子中的卡只能移到余5里,余5的箱子只能移到余4里。最终箱子编号为4;
因为最后不能移动的箱子为1,3,4,所以,%6=0,2,5的步数为奇数。将所有奇数的做Nim即可。
AC代码如下:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int T,t,n,m;
int main()
{
int i,j,k,S;
scanf("%d",&T);
for(t=1;t<=T;t++)
{
scanf("%d",&n);
S=0;
for(i=1;i<=n;i++)
{
scanf("%d",&k);
if(i%6==0 || i%6==2 || i%6==5)
S^=k;
}
if(S==0)
printf("Case %d: Bob\n",t);
else
printf("Case %d: Alice\n",t);
}
}