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
根据staircase nim游戏的结论
假设移动的终点为0,那么只要考虑奇数位的Nim和就行了
如果不是按位移动的,那么就变成距离终点步数为奇数的Nim和
画图归纳,发现当i%6等于0,2,5时,到终点步数为奇数
取那些位的Nim和
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int ans,n;
int gi()
{
int x=;char ch=getchar();
while (ch<''||ch>'') ch=getchar();
while (ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x;
}
int main()
{int i,T,TT,x;
cin>>T;
TT=T;
while (T--)
{
cin>>n;
ans=;
for (i=;i<=n;i++)
{
x=gi();
if (i%==||i%==||i%==)
ans^=x;
}
if (ans) printf("Case %d: Alice\n",TT-T);
else printf("Case %d: Bob\n",TT-T);
}
}
 

HDU3389 Game的更多相关文章

随机推荐

  1. Linux 终端 Bash 常用快捷键介绍及经验

    1. 最重要的自动补全 命令 解释 Tab 自动补全 不用多说,自动补全可以节省大量时间 2. 编辑跳转 命令 解释 Ctrl + A 跳转到当前行首 Ctrl + E 跳转到当前行末 Alt + F ...

  2. 用Python登录好友QQ空间点赞

    记得之前跟我女票说过,说要帮她空间点赞,点到999就不点了.刚开始还能天天记得,但是后来事情一多,就难免会忘记,前两天点赞的时候忽然觉得这样好枯燥啊,正好也在学Python,就在想能不能有什么方法能自 ...

  3. Alpha第三天

    Alpha第三天 听说 031502543 周龙荣(队长) 031502615 李家鹏 031502632 伍晨薇 031502637 张柽 031502639 郑秦 1.前言 任务分配是VV.ZQ. ...

  4. 算法——算法时间复杂度的计算和大O阶的推导

    在算法分析中,我们将语句总的执行次数记为T(n)进而分析T(n)随n的变化情况确认T(n)的数量级.一般情况下,T(n)随n增大变化最缓慢的算法为最优算法. 根据定义,T(n)的求法是很简单的,也就是 ...

  5. node创建第一个应用

    如果我们使用PHP来编写后端的代码时,需要Apache 或者 Nginx 的HTTP 服务器,并配上 mod_php5 模块和php-cgi. 从这个角度看,整个"接收 HTTP 请求并提供 ...

  6. 微信开发之SVN提交代码与FTP同步到apache的根目录

    SVN是协同开发的,版本控制器,就是几个人同时开发,可以提交代码到SVN服务器,这样就可以协同开发,一般是早上上班首先更新下代码,然后自己修改代码 工作一天之后,修改代码之后,下班之前,更新代码,然后 ...

  7. 你考虑清楚了吗就决定用 Bootstrap ?

    近年来,在前端项目中, Bootstrap 已经成为了一个非常受欢迎的工具. Bootstrap 的确有很多优点,然而,如果你的团队中恰好有一个专职的前端工程师.那我推荐你们不要使用 Bootstra ...

  8. api-gateway实践(06)新服务网关 - 请求监控

    一.实时监控 用户点击服务实例,系统显示服务实例-version下的api列表, 用户点击某个api的如下两个图标 1.API请求次数监控 横轴:时间,粒度为分钟 纵轴:请求访问次数 展示:失败数(红 ...

  9. java基础总结(1)安装jdk

           卸载java java -version yum remove java yum groupjava java        安装java tar -zxvf jdk-8u60-linu ...

  10. linux下的Shell编程(3)shell里的流程控制

    if 语句 if 表达式如果条件命令组为真,则执行 then 后的部分.标准形式: if 判断命令,可以有很多个,真假取最后的返回值 then 如果前述为真做什么 [ # 方括号代表可选,别真打进去了 ...