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. thinkphp3.2 where 条件查询 复查的查询语句

    复查的查询语句 有的时候,我们希望通过一次的查询就能解决问题,这个时候查询条件往往比较复杂,但是却比多次查询库来的高效. 实在是搞不定的话就直接用$where[‘_string’] = ‘xxxx’, ...

  2. LAMP架构的搭建

    什么是LAMP架构? L : Linux,2.6.18-308.el5(redhat5.8) A :Apache,httpd 2.4.4 M :  mysql-5.5.28  P : php-5.4. ...

  3. Wind Of Change

    Wind of change until the end  变革的风一直吹直至最后 You will see that I will be your friend 你会看见我成为你的朋友 If you ...

  4. IOS多网卡抓包

    linux下libpcap支持从多网卡抓包,设置为any即可 在IOS或者mac上就无法通过次方法抓取所有网卡报文 1.通过设置libevent事件回调,每个网卡注册读事件, fd通过 pd = pc ...

  5. 【Remove Duplicates from Sorted List 】cpp

    题目: 第一次刷的时候漏掉了这道题. Given a sorted linked list, delete all duplicates such that each element appear o ...

  6. Python IO关于mode参数的问题

    关于open()的mode参数: 'r':读 'w':写 'a':追加 'r+' == r+w(可读可写,文件若不存在就报错(IOError)) 'w+' == w+r(可读可写,文件若不存在就创建) ...

  7. flask 基础ssti注入

    源代码地址 (请用python2.7运行,python3有点出入) 注入点: 不是返回的静态模板而是反回模板字符串变得让客户端可以控制. XSS 这里直接 http://39.105.116.195: ...

  8. Kotlin中when表达式的使用:超强的switch(KAD 13)

    作者:Antonio Leiva 时间:Feb 23, 2017 原文链接:https://antonioleiva.com/when-expression-kotlin/ 在Java(特别是Java ...

  9. 孤荷凌寒自学python第八天 初识Python的序列之元组

    孤荷凌寒自学python第八天 Python的序列之元组 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) (同步音频笔记:https://www.ximalaya.com/keji/19103 ...

  10. 浅谈传输层协议TCP和UDP

    在当今因特网的层次结构中,传输层的协议主要有两种,其一为Transmission Control Protocol,即TCP:其二为User Datagram Protocol,即UDP. 1.TCP ...