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. Struts2——第一个helloworld页面

    struts2是一个较为成熟的mvc框架,先看看怎么配置struts2并且产生helloworld页面. 首先从官网下载struts2,http://struts.apache.org/downloa ...

  2. C语言第三周作业---单层循环

    一.PTA实验作业 题目1 1.实验代码 int N = 0,i; char sex; float a[9], height; scanf("%d\n", &N); for ...

  3. 201621123068 作业07-Java GUI编程

    1. 本周学习总结 1.1 思维导图:Java图形界面总结 2.书面作业 1. GUI中的事件处理 1.1 写出事件处理模型中最重要的几个关键词. 注册.事件.事件源.监听 1.2 任意编写事件处理相 ...

  4. win10 安装mingw ruby rails

    原文可以参考 https://ruby-china.org/topics/17581 在window10 安装ruby rails https://rubyinstaller.org/download ...

  5. nyoj 鸡兔同笼

    鸡兔同笼 时间限制:3000 ms  |  内存限制:65535 KB 难度:1   描述 已知鸡和兔的总数量为n,总腿数为m.输入n和m,依次输出鸡和兔的数目,如果无解,则输出"No an ...

  6. python 一篇搞定所有的异常处理

    一:什么是异常? 异常即是一个事件,该事件会在程序执行过程中发生,影响了程序的正常执行. 一般情况下,在python无法正常处理程序时就会发生一个异常(异常是python对象,表示一个错误) 异常就是 ...

  7. Session 和 Cookie 区别

    会话跟踪是Web程序中常用的技术,用来跟踪用户的整个会话.常用的会话跟踪技术是Cookie与Session.==Cookie通过在客户端记录信息确定用户身份,Session通过在服务器端记录信息确定用 ...

  8. 常用Mysql数据库操作语句

    用户管理: 1.新建用户: 语法msyql>CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 说明: username - 你将创建 ...

  9. kali rolling更新源之gpg和dirmngr问题

    1.编辑 /etc/apt/source.list gedit /etc/apt/sources.list 输入更新源,可以选任何可用更新源,这里设置官方源 deb http://http.kali. ...

  10. ZendStudio的使用技巧

    为了使得ZendStudio支持volt模版可以在首选项中的ContentType加上.volt就行 在ZendStudio中的->help中有一个installNewssoftWare,然后会 ...