Alice and Bob are playing game of Misère Nim. Misère Nim is a game playing on k piles of stones, each pile containing one or more stones. The players alternate turns and in each turn a player can select one of the piles and can remove as many stones from that pile unless the pile is empty. In each turn a player must remove at least one stone from any pile. Alice starts first. The player who removes the last stone loses the game.

Input

Input starts with an integer T (≤ 200), denoting the number of test cases.

Each case starts with a line containing an integer k (1 ≤ k ≤ 100). The next line contains k space separated integers denoting the number of stones in each pile. The number of stones in a pile lies in the range [1, 109].

Output

For each case, print the case number and 'Alice' if Alice wins otherwise print 'Bob'.

Sample Input

3

4

2 3 4 5

5

1 1 2 4 10

1

1

Sample Output

Case 1: Bob

Case 2: Alice

Case 3: Bob

题意:

有n堆石子,每堆石子里面至少有一个石子,有A、B两人。A先取,取完所有石子的一方获胜,问当双方都采取最优策略时,谁能获胜。

思路:

nim博弈模板,谁面临平衡态势谁就会输。

特判一种情况:当每一堆石子的个数全部都为1的时候,这个时候只能每次拿一个,根据1的奇偶性进行判断。

 #include<stdio.h>

 int main()
{
int t,tt=;
scanf("%d",&t);
while(t--)
{
int n,xx;
scanf("%d",&n);
int x=,flag=;
for(int i=; i<n; i++)
{
scanf("%d",&xx);
if(xx!=)
{
flag=;
}
x^=xx;
}
if(flag==)
{
if(n%==)
printf("Case %d: Alice\n",tt++);
else
printf("Case %d: Bob\n",tt++);
}
else
{
if(x!=)
printf("Case %d: Alice\n",tt++);
else
printf("Case %d: Bob\n",tt++);
}
}
return ;
}

LightOJ-1253-Misere Nim-nim博弈的更多相关文章

  1. LightOJ 1253 Misere NIM(反NIM博弈)

    Alice and Bob are playing game of Misère Nim. Misère Nim is a game playing on k piles of stones, eac ...

  2. (转)巴氏(bash)威佐夫(Wythoff)尼姆(Nim)博弈之模板

    感谢:巴氏(bash)威佐夫(Wythoff)尼姆(Nim)博弈之模板 转自:http://colorfulshark.cn/wordpress/巴氏(bash)威佐夫(wythoff)尼姆(nim) ...

  3. Light OJ 1253 Misere Nim (尼姆博弈(2))

    LightOJ1253 :Misere Nim 时间限制:1000MS    内存限制:32768KByte   64位IO格式:%lld & %llu 描述 Alice and Bob ar ...

  4. nim博弈 LightOJ - 1253

    主要是写一下nim博弈的理解,这个题有点奇怪,不知道为什么判断奇偶性,如果有大佬知道还请讲解一下. //nim博弈 //a[0]~a[i] 异或结果为k 若k=0 则为平衡态 否则为非平衡态 //平衡 ...

  5. LightOJ 1186 Icreable Chess(Nim博弈)

    You are given an n x n chess board. Only pawn is used in the 'Incredible Chess' and they can move fo ...

  6. zoj3591 Nim(Nim博弈)

    ZOJ 3591 Nim(Nim博弈) 题目意思是说有n堆石子,Alice只能从中选出连续的几堆来玩Nim博弈,现在问Alice想要获胜有多少种方法(即有多少种选择方式). 方法是这样的,由于Nim博 ...

  7. HDU 5795 A Simple Nim (博弈 打表找规律)

    A Simple Nim 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5795 Description Two players take turns ...

  8. poj 2975 Nim(博弈)

    Nim Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5232   Accepted: 2444 Description N ...

  9. HDU 3032 Nim or not Nim?(博弈,SG打表找规律)

    Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  10. Poj1704:staircase nim【博弈】

    题目大意:有一个无限长的一维的棋盘,棋盘上N个格子放置着棋子.两个人轮流操作,每次操作能选择其中一个棋子向左移动,但不能越过其它棋子或者两枚棋子放在同一格中,最后不能操作的人算输,问先手是否必胜? 思 ...

随机推荐

  1. NGINX配置之一:日志篇

    打开nginx.conf配置文件: vi /usr/local/nginx/conf/nginx.conf 日志部分内容: 日志生成的到Nginx根目录logs/access.log文件,默认使用“m ...

  2. js分割url提取参数

    //分割url提取参数 var url = Window.location.search;//获取url地址?至结尾的所有参数 //key(需要检错的键) url(传入的需要分割的url地址) fun ...

  3. jmeter 环境java监视和管理控制

    打开这个小工具的步骤很简单,如果你已经配置好了Jmeter运行的环境,那么你也就不用去做其他的配置,直接 点击:开始——>运行——>输入cmd——>然后在出现的命令行界面输入“jco ...

  4. springboot启动失败( No active profile set, falling back to default profiles: default)

    问题: springboot启动失败( No active profile set, falling back to default profiles: default) 解决方法 在pom.xml文 ...

  5. 2019杭电多校第三场hdu6608 Fansblog(威尔逊定理)

    Fansblog 题目传送门 解题思路 Q! % P = (P-1)!/(P-1)...(Q-1) % P. 因为P是质数,根据威尔逊定理,(P-1)!%P=P-1.所以答案就是(P-1)((P-1) ...

  6. 拾遗:Git 常用操作回顾

    温故而知新,可以为师矣. Git 布局 工作区---->暂存区---->本地仓库---->远程仓库 Create Repository git init PATH git add P ...

  7. Git 学习第二天(三)

    删除文件: 先新建一个test文件到webgit版本库中,然后 git add            git commit 当然,我们可以在文件夹中删除文件,git 也提供了命令 rm file 此时 ...

  8. 【转】HTML5标签使用的常见误区

    最近组内进行 HTML5标签的学习,方法呢就是大家每人挑选几个标签,自己先去学习,然后给大家作讲解.这个过程大家还是挺有收获的.但是现在HTML5还处在草案阶 段,有些新的标签元素的解释也是经常有变化 ...

  9. 深入理解JAVA虚拟机原理之内存分配策略(二)

    更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680 1.对象优先在Eden分配 大多情况,对象在新生代Eden区分配.当Eden区没 ...

  10. 大道浮屠诀---NBU7.7.3_oracle11G单机-单机(异机恢复WINDOWS2008平台)

    现有环境说明: 一台WINDOWS2008R2:安装有NBU7.7.3,作为服务端 一台WINDOWS2008R2:安装有oracle11.2.0.3,作为数据库服务器 现假设数据库意外崩溃,需要进行 ...