Game |
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
Total Submission(s): 46 Accepted Submission(s): 42 |
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 |
Author
题目大意:
B<A && (A+B)%2=1 && (A+B)%3=0. 选择两个盒子,若 A B 满足这个关系,则能将 A 中转移任意个卡片到 B 中。
不能转移就输了。
思路:
我们首先打个表,观察 盒子可以如何转移。
对于 某个盒子,转移到最后,他的步数要么全是偶数,要么全是奇数,打出表来就可以观察到的。
这样的话可以转化到阶梯博弈上来了,我们只需要NIM 这些奇数步转移的盒子就可以的到答案。
为什么对于偶数步的盒子我们可以不用管呢? 下面给出我的一些证明:
如果对于当前的状态,(所有奇数步盒子 nim 得到答案是 必胜)
那么我们按照必胜的步骤来移动奇数步盒子,如果对手移动奇数步盒子,那么我们继续按照必胜步骤移动。
如果对手移动偶数步盒子,那么我们就将对手移动的这些卡片移动到下一个盒子里,也就是保持原先的状态。这样走下去,结果一定是之前判断得到的答案。
AC代码:
|
HDU 3389 Game 阶梯博弈
最新推荐文章于 2021-02-09 19:57:05 发布