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. MLT教程:从BXL文件导入Altium Designer原理图封装和PCB封装

    在TI官网的封装文件中提供弄BXL文件可以导出Altium Designer的封装库和原理图库. 这个界面往下面拉会看到: 然后可以下载各种封装的bxl文件了.下面视频说明bxl文件如何导出成功. 如 ...

  2. PTA 7-12(图) 社交网络图中结点的“重要性”计算 最短路

    7-12(图) 社交网络图中结点的“重要性”计算 (30 分) 在社交网络中,个人或单位(结点)之间通过某些关系(边)联系起来.他们受到这些关系的影响,这种影响可以理解为网络中相互连接的结点之间蔓延的 ...

  3. python基础之继承实现原理、子类调用父类的方法、封装

    继承实现原理 python中的类可以同时继承多个父类,继承的顺序有两种:深度优先和广度优先. 一般来讲,经典类在多继承的情况下会按照深度优先的方式查找,新式类会按照广度优先的方式查找 示例解析: 没有 ...

  4. 20145202马超 《Java程序设计》第七周学习总结

    Arrays:用于操作数组的工具类. 里面都是静态方法. asList:将数组变成list集合. 把数组变成集合的好处:可以使用集合的思想来操作数组中的元素. 将数组变成集合的时候不可以使用集合的增删 ...

  5. 10,python开发之virtualenv与virtualenvwrapper

      在使用 Python 开发的过程中,工程一多,难免会碰到不同的工程依赖不同版本的库的问题: 亦或者是在开发过程中不想让物理环境里充斥各种各样的库,引发未来的依赖灾难. 此时,我们需要对于不同的工程 ...

  6. FileStream流媒体

    class Program { static void Main(string[] args) { string source = @"mana.mp4"; string targ ...

  7. Linux 批量删除文件后缀

    例子: [zengs@gene CASP9]$ lscasp9.ids T0526 T0538 T0550 T0562 T0574 T0586 T0598 T0610 T0622 T0634T0515 ...

  8. 《Cracking the Coding Interview》——第3章:栈和队列——题目6

    2014-03-19 03:01 题目:给定一个栈,设计一个算法,在只使用栈操作的情况下将其排序.你可以额外用一个栈.排序完成后,最大元素在栈顶. 解法:我在草稿纸上试了试{1,4,2,3}之类的小例 ...

  9. Vue 使用Spread.js没有层级关系(隐藏与显示)

    Vue 使用Spread.js没有层级关系(隐藏与显示) 1.vue会给元素加一个监控属性.去掉 spread.js没有层级关系过半是column中值的问题

  10. lua中如何识别C语言中的struct

    不如用c写比较简单呢 都要在lua中解析好数据结构,不过也可以用ffi呢...proto.lua