Again Stone Game
Alice and Bob are playing a stone game. Initially there are n piles of stones and each pile contains some stone. Alice stars the game and they alternate moves. In each move, a player has to select any pile and should remove at least one and no more than half stones from that pile. So, for example if a pile contains 10 stones, then a player can take at least 1 and at most 5 stones from that pile. If a pile contains 7 stones; at most 3 stones from that pile can be removed.
Both Alice and Bob play perfectly. The player who cannot make a valid move loses. Now you are given the information of the piles and the number of stones in all the piles, you have to find the player who will win if both play optimally.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a line containing an integer n (1 ≤ n ≤ 1000). The next line contains n space separated integers ranging in [1, 109]. The ith integer in this line denotes the number of stones in the ith pile.
Output
For each case, print the case number and the name of the player who will win the game.
Sample Input
5
1
1
3
10 11 12
5
1 2 3 4 5
2
4 9
3
1 3 9
Sample Output
Case 1: Bob
Case 2: Alice
Case 3: Alice
Case 4: Bob
Case 5: Alice
/*
* @Author: lyuc
* @Date: 2017-04-26 21:32:51
* @Last Modified by: lyuc
* @Last Modified time: 2017-04-26 22:13:13
*/ /*题意:给你n堆石子每次你可以选择一堆,至少取一个,最多不能超过一半,比如7个的时候,你最多取3个谁不
* 能取了就输了
*
*初步思路:想到了SG,但是没办法数据量太大了,只能打表找规律,找到规律,如果n为奇数sg(n)=sg(n/2)
* 如果是偶数sg(n)=n/2
*/
#include <bits/stdc++.h>
using namespace std;
int t,n;
int num;
int sg[];
int hash[];
int res;
//sg打表
void init(){
memset(sg,,sizeof sg);
for(int i=;i<;i++){
memset(hash,,sizeof hash);
for(int j=;j+j<=i;j++){
hash[sg[i-j]]=;
}
for(int j=;j<;j++){
if(hash[j]==){
sg[i]=j;
break;
}
}
}
}
int main(){
// freopen("in.txt","r",stdin);
scanf("%d",&t);
for(int ca=;ca<=t;ca++){
printf("Case %d: ",ca);
res=;
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&num);
while(num%!=){
num/=;
}
res^=num;
}
printf(res==?"Bob\n":"Alice\n");
}
return ;
}
Again Stone Game的更多相关文章
- POJ1740A New Stone Game[组合游戏]
A New Stone Game Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5769 Accepted: 3158 ...
- timus 1180. Stone Game 解题报告
1.题目: 1180. Stone Game Time limit: 1.0 secondMemory limit: 64 MB Two Nikifors play a funny game. The ...
- HDU 4048 Zhuge Liang's Stone Sentinel Maze
Zhuge Liang's Stone Sentinel Maze Time Limit: 10000/4000 MS (Java/Others) Memory Limit: 32768/327 ...
- POJ 1740 A New Stone Game
A New Stone Game Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5453 Accepted: 2989 ...
- Light OJ 1296 - Again Stone Game (博弈sg函数递推)
F - Again Stone Game Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- poj 1115 Lifting the Stone 计算多边形的中心
Lifting the Stone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- 【POJ】A New Stone Game(博弈论)
http://poj.org/problem?id=1740 题目大意就是,对于n堆石子,每堆若干个,两人轮流操作,每次操作分两步,第一步从某堆中去掉至少一个,第二步(可省略)把该堆剩余石子的一部分分 ...
- HDUOJ--------A simple stone game(尼姆博弈扩展)(2008北京现场赛A题)
A simple stone game ...
- POJ 1740 A New Stone Game(普通博弈)
A New Stone Game 题意: 对于n堆石子,每堆若干个,两人轮流操作,每次操作分两步,第一步从某堆中去掉至少一个,第二步(可省略)把该堆剩余石子的一部分分给其它的某些堆.最后谁无子可取即输 ...
- POJ 3922A Simple Stone Game
题目链接 A Sample Stone Game 题目大意:给定n,k,表示最初时有n个石头,两个人玩取石子游戏,第一个人第一次可以取1~n-1个石头,后面每个人最多可以拿走前面一个人拿走的个数的K倍 ...
随机推荐
- pycharm 2017新建文件添加编码方式等
file->setting->Editor->File and Code Templates->Python Script 添加 #!/usr/bin/python3# -*- ...
- Java笔记—— 类与对象的几个例子
问题1 按要求编写java应用程序: 编写西游记人物类,属性有:身高,名字和武器.方法有:显示名字,显示武器. 在main方法中创建两个对象.猪八戒和孙悟空,并分别为他们的两个属性名字和武器赋值,最后 ...
- 如何实现跨 Docker 主机存储?- 每天5分钟玩转 Docker 容器技术(73)
从业务数据的角度看,容器可以分为两类:无状态(stateless)容器和有状态(stateful)容器. 无状态是指容器在运行过程中不需要保存数据,每次访问的结果不依赖上一次访问,比如提供静态页面的 ...
- SpringBoot开发案例之mail中文附件乱码
前一段时间做过一个邮件发送的服务,以前大体都测试过,文本.图片.附件都是没有问题的,可有同事反应发送的附件名称有中文乱码,类似如下截图展示: 咋一看不像乱码,抱着试试看的态度,为MimeMessage ...
- swift 开发学习问题
1 UITableViewController 问题: [UITableView dequeueReusableCellWithIdentifier:forIndexPath:], unable to ...
- java初学者(新手)应该如何选择学习教材与网站
作者:天天向上 1.学习教材选择推荐<JAVA核心技术>,想多看点代码多练习可以找<java开发实战经典>&amp;lt;img src="https ...
- http://codeforces.com/contest/535/problem/C
C. Tavas and Karafs time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Max Consecutive Ones
Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...
- Redis info 参数详解
Redis Info 命令以一种易于理解和阅读的格式,返回关于 Redis 服务器的各种信息和统计数值. 通过给定可选的参数 section ,可以让命令只返回某一部分的信息: server : 一般 ...
- VBA.NET 系统可行性分析模板
系统可行性分析 1. 技术可行性分析 前提: 系统不知在Window系统中,开发环境不受限制:系统以C/S结构为主,提供大量的数据操作:主要用VB.NET开发,提高安全性和访问效率. 基本要求 客户 ...