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, 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博弈的更多相关文章
- 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 ...
- (转)巴氏(bash)威佐夫(Wythoff)尼姆(Nim)博弈之模板
感谢:巴氏(bash)威佐夫(Wythoff)尼姆(Nim)博弈之模板 转自:http://colorfulshark.cn/wordpress/巴氏(bash)威佐夫(wythoff)尼姆(nim) ...
- Light OJ 1253 Misere Nim (尼姆博弈(2))
LightOJ1253 :Misere Nim 时间限制:1000MS 内存限制:32768KByte 64位IO格式:%lld & %llu 描述 Alice and Bob ar ...
- nim博弈 LightOJ - 1253
主要是写一下nim博弈的理解,这个题有点奇怪,不知道为什么判断奇偶性,如果有大佬知道还请讲解一下. //nim博弈 //a[0]~a[i] 异或结果为k 若k=0 则为平衡态 否则为非平衡态 //平衡 ...
- 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 ...
- zoj3591 Nim(Nim博弈)
ZOJ 3591 Nim(Nim博弈) 题目意思是说有n堆石子,Alice只能从中选出连续的几堆来玩Nim博弈,现在问Alice想要获胜有多少种方法(即有多少种选择方式). 方法是这样的,由于Nim博 ...
- HDU 5795 A Simple Nim (博弈 打表找规律)
A Simple Nim 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5795 Description Two players take turns ...
- poj 2975 Nim(博弈)
Nim Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5232 Accepted: 2444 Description N ...
- 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 ...
- Poj1704:staircase nim【博弈】
题目大意:有一个无限长的一维的棋盘,棋盘上N个格子放置着棋子.两个人轮流操作,每次操作能选择其中一个棋子向左移动,但不能越过其它棋子或者两枚棋子放在同一格中,最后不能操作的人算输,问先手是否必胜? 思 ...
随机推荐
- Python_day01——变量
变量 1.声明变量 name="钱成龙" 变量定义的规则: 变量名只能是 字母.数字或下划线的任意组合 变量名的第一个字符不能是数字 关键字不能声明为变量名 2.变量类型 整 ...
- DesktopLoader服务程序
program DesktopLoader; //{$APPTYPE CONSOLE} uses Windows,WinSvc,ShellApi; var s:String; iDesktops,jD ...
- 天照(amaterasu)
天照(amaterasu) 有些时候,出题人真的不想写背景. 总而言之,天照现在有一个长度为 $ N $ 序列,她有 $ M $ 次询问,对于第 $ i $ 次询问 $ l_i,r_i,x_i $ 你 ...
- python re模块使用
re.findall() 查找字符 从字符串中找出符合模式的字符序列:findall(模式(正则表达式),目标字符串), 返回值为list类型,list元素为匹配出的各个字符串如: import re ...
- 我看Spring MVC系列(一)
1.Spring MVC是什么: Spring MVC:Spring框架提供了构建Web应用程序的全功能MVC模块. 2.Spring helloWorld应用(基于Spring 4.2) 1.添加S ...
- 由Resin引发的java.lang.IllegalArgumentException: object is not an instance of declaring class(反射中使用)思考
文章目录 背景 原因 解决办法 背景 在java agent中抓取Resin的 某些方法,在invoke的时候出现错误 java.lang.IllegalArgumentException: obje ...
- nrm的安装使用
1.利用npm来安装nrm,且是全局安装nrm包 npm i nrm -g 2.使用nrm ls查看当前所有可用的镜像源地址以及当前所使用的镜像源地址 3.使用nrm use npm 或者nrm us ...
- Win7环境下VS2010配置Cocos2d-x-2.1.4最新版本的开发环境(亲测)
写这篇博客时2D游戏引擎Cocos2d-x的最新版本为2.1.4,记得很久以前使用博客园博主子龙山人的一篇博文<Cocos2d-x win7+vs2010配置图文详解(亲测)>成功配置 ...
- 36-Ubuntu-用户管理-01-新建用户useradd
创建用户/设置密码/删除用户/确认用户信息 序号 命令 作用 说明 01 sudo useradd -m -g 组名 新建用户名 添加新用户 -m 自动建立用户家目录 -g 指定用户所在的组,否则会建 ...
- Oracle中NEXTVAL 和 CURRVAL的使用
能够通过在 SQL 语句中使用 NEXTVAL 或 CURRVAL 运算符来訪问序列的值.必须用以 sequence.NEXTVAL 或sequence.CURRVAL 格式驻留在同一个数据库中的序列 ...