N个盒子从1--N编号,每个盒子有若干个卡片,每次操作可以选择两个盒子A,B,编号满足 B<A && (A+B)%2=1 && (A+B)%3=0. ,从A中将若干张卡片(大于0)放到B中,最先无法操作的一方输,给出N个盒子的卡片数求胜负。一眼看上去好像跟NIM游戏没啥关系...把小的数据列举一下,在每次选择都令A,B尽可能相近的情况下,发现卡片的移动只有三条路线:
1 2 7 8 13 14 19...
3 6 9 12 15 18...
4 5 10 11 16 17....
然后两两取出来,把这N个数分成两类,得到
1 2
3 6
4 5
7 8
9 12
10 11
13 14
15
16 17
对于每一行都可以把右边的卡片放到左边当中,而对左侧,可以把卡片放到右侧向上三行的位置,进一步可以发现,右侧每一个位置至少都有一种方法把卡片移动到左侧,那么可以把游戏模型转化一下,把右侧的卡片全部移动到左侧,不能移动的一方输,这样就成了在右侧做一个NIM游戏了。因为右侧每一个位置都可以向左移动卡片,所以若一方选择把左边的卡片移动到右边,另一方可以将相同的卡片放回左侧,这样结果不变...所以最后这题实际上就是个数列找规律了......
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
int n,m,p,q;
bool check(int t)
{
if (t % 3==0 && t % 2==1) return false;
if (t % 3==1) return false;
return true;
}
int main()
{
int tt;
scanf("%d",&tt);
int ct=0;
while (tt--)
{
ct++;
scanf("%d",&n);
int ans=0;
for (int i=1; i<=n; i++)
{
scanf("%d",&m);
if (check(i)) ans=ans^m;
}
printf("Case %d: ",ct);
if (!ans) puts("Bob");
else puts("Alice");
}
return 0;
}