Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u

Submit Status

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
 

Source

The 5th Guangting Cup Central China Invitational Programming Contest
题意:有t组数据。每组数据有n个盒子,这n个盒子编号为12345678......。(注意不是从0开始的)
   每个盒子中有一定量的卡片。每次取编号为B和编号为A的盒子, 要求满足
   B<A && (A+B)%2=1 && (A+B)%3=0,把A中的任意数量的卡片转移给B,谁不能再转移了谁输。
题解:阶梯博弈,只需要考虑步数为奇数的盒子,步数为偶数的盒子不需要考虑。
   在本题中编号为1,3,4的盒子不能转移卡片,其余盒子均可转移。例如:
   2->1,   5->4,   6->3,   7->2   ,8->1,   9->6...
   其本质为有n级阶梯,我们在%3的余数中进行转移0->0,   1->2,   2->1;最后的结果
   一定是1或者3或者4,这些盒子中卡片转移的步数的奇偶性是一定的。为什么这么说呢?
   因为即使有些盒子例如编号11的盒子,有11->4和11->10->8->1两种选择,但是这
   两种选择的步数的奇偶性是相同的,都是奇数,所以奇偶性是一定的。
   所以我们把这个阶梯博弈转化为尼姆博弈就行了,对步数为奇数的盒子进行尼姆博弈
   在纸上多写几个数或者用打表的方法可以发现如下规律:
   盒子编号模6为0,2,5的位置的移动步数为奇,其余为偶。
   推到这里就很好实现了。
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int t,cas=;
cin>>t;
while(t--)
{
int n,data,ans=;
cin>>n;
for(int i=;i<=n;i++)
{
cin>>data;
if(i%==||i%==||i%==)
ans^=data;
}
if(ans)
printf("Case %d: Alice\n",cas++);
else
printf("Case %d: Bob\n",cas++);
}
return ;
}

HDU 3389 Game (阶梯博弈)的更多相关文章

  1. HDU 3389 阶梯博弈变形

    n堆石子,每次选取两堆a!=b,(a+b)%2=1 && a!=b && 3|a+b,不能操作者输 选石子堆为奇数的等价于选取步数为奇数的,观察发现 1 3 4 是无法 ...

  2. hdu 3389 Game (阶梯博弈)

    #include<stdio.h> int main() { int t,n,ans; int i,j,x; scanf("%d",&t); ;j<=t; ...

  3. hdu 3389 阶梯博弈

    题意:1-N带编号的盒子,当编号满足A>B && A非空 && (A + B) % 3 == 0 && (A + B) % 2 == 1则可以从A ...

  4. HDU 4315:Climbing the Hill(阶梯博弈)

    http://acm.hdu.edu.cn/showproblem.php?pid=4315 题意:有n个人要往坐标为0的地方移动,他们分别有一个位置a[i],其中最靠近0的第k个人是king,移动的 ...

  5. HDU 4315 Climbing the Hill(阶梯博弈)

    http://acm.hdu.edu.cn/showproblem.php?pid=4315 题意:由上至下有多个格子,最顶端的是山顶,有多个球,其中有一个球是king,每次可以将球向上移动任意个格子 ...

  6. HDU 4315 阶梯博弈变形

    n个棋子,其中第k个是红色的,每个棋子只能往上爬,而且不能越过.重叠其他棋子,谁将红色棋子移到顶部谁赢. 由于只能往上爬,所以很像阶梯博弈.这题有2个限制,棋子不能重叠,有红棋存在 首先不考虑红色棋, ...

  7. HDU 4315 Climbing the Hill (阶梯博弈转尼姆博弈)

    Climbing the Hill Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Su ...

  8. 【hdu 3389】Game

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...

  9. POJ1704 Georgia and Bob (阶梯博弈)

    Georgia and Bob Time Limit: 1000MS   Memory Limit: 10000KB   64bit IO Format: %I64d & %I64u Subm ...

随机推荐

  1. 477. Total Hamming Distance

    class Solution { public: int totalHammingDistance(vector<int>& nums) { ; ; i < ; i++) { ...

  2. VUE前端无法启动

    cd 到client中,使用npm run dev ,一直卡着也不报错,启动不了项目 可以直接使用 ,需要进入root目录进行 cnpm install npm -g

  3. POJ:3185-The Water Bowls(枚举反转)

    The Water Bowls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7402 Accepted: 2927 Descr ...

  4. 方法的重写(Override)与重载(Overload)的含义与区别

    1.Override(重写) 两同,两小,一大 两同:方法名相同,参数列表相同 两小:抛出的异常要小于等于父类,返回值类型要小于等于父类 一大:访问权限要大于等于父类 2.Overload(重载) 方 ...

  5. pdfmake实现中文支持,解决中文乱码问题

    引言:当初自己为了在项目中bootstrap-table中实现导出pdf,使用的pdfmake,但是pdfmake默认使用的不是中文字体,实现pdfmake使用中文字体主要就是编译新的vfs_font ...

  6. ST表学习

    啊谈不上学习了.复习一下原理留一下板子. $f\left[i,j \right]$表示以$i$为起点,区间长度为${2}^{j}$的区间最值.以最小值为例,即 $min\left(a\left [ k ...

  7. 8 定制10MINs 3

    1. <div class="ui inverted red basic segment"> <h3 class="ui header"> ...

  8. 《Cracking the Coding Interview》——第9章:递归和动态规划——题目2

    2014-03-20 02:55 题目:从(0, 0)走到(x, y),其中x.y都是非负整数.每次只能向x或y轴的正方向走一格,那么总共有多少种走法.如果有些地方被障碍挡住不能走呢? 解法1:如果没 ...

  9. 《Cracking the Coding Interview》——第6章:智力题——题目4

    2014-03-20 01:02 题目:无力描述的一道智力题,真是货真价实的智力题,让我充分怀疑自己智力的智力题.有兴趣的还是看书去吧. 解法:能把题目看懂,你就完成80%了,用反证法吧. 代码: / ...

  10. Lua语言中文手册 转载自网络

    Programming in LuaCopyright ® 2005, Translation Team, www.luachina.net Programming in LuaProgramming ...