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.
InputThe 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.OutputFor 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

先来解释一下阶梯博弈吧~~

阶梯博弈等效为奇数号阶梯的尼姆博弈。

解释:

假设我们是先手。我们按照尼姆博弈的原则进行第一次移动。

如果对方移动奇数号阶梯的石子,我们继续按照尼姆博弈的原则移动。

如果对方移动的是偶数号阶梯的石子,及对方将偶数号阶梯的石子移动到了奇数号(对奇数号产生了影响)我们就接着将对方移动到奇数号的石子再向下移动一个台阶,移动到偶数号。

这就意味着在偶数号的棋子对我们的博弈是没有影响的。

那为什么不是偶数号阶梯的尼姆博弈呢

你sa呀,偶数号的话,对手移动奇数号到0(地面),那状态就改变了呀

下面说题啦~~~~~~~

刚开始理解错题意了,不过也没看出来是阶梯博弈,引入一张图来解释(来自某位大神的博客)

选择盒子需要满足的条件:奇数且是三的倍数。

1盒与2盒----1+2 = 3 可以满足,从2盒拿卡片到1盒-----1盒无法移动卡片

3盒必定是和另一个三的倍数盒才能满足条件----------3盒无法移动卡片

。。。。。。。。。。。。。

同理 可以得出1 ,3 , 4是无法移动卡片的 , 而其他的总是可以通过几步操作来达到1 ,3 ,4 .

根据图可以得出当n%6 == 0 || 2 || 5 时(循环从1 开始),我们需要移动的步数是奇数, 其他为偶数。

这样我们就可以用阶梯博弈来写了。

下面贴上代码:

#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
	int t , n ,a;
	scanf("%d" , &t);
	int num=1;
	while(t--)
	{
		int res = 0;
	
		scanf("%d" ,&n);
		for(int i = 1; i<=n;i++)
		{
			scanf("%d" , &a);
			if(i % 6==0||i%6==2||i%6==5)
			{
				res ^= a;
			}
		}
		if(res)
		{
			
		printf("Case %d: Alice\n" , num);
		}
		else
		{
			printf("Case %d: Bob\n",num);
		}
		num++;
	}
	return 0;
 }