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个格子放置着棋子.两个人轮流操作,每次操作能选择其中一个棋子向左移动,但不能越过其它棋子或者两枚棋子放在同一格中,最后不能操作的人算输,问先手是否必胜? 思 ...
随机推荐
- 组合数学(math)
组合数学(math) 题目描述 为了提高智商,zjy开始学习组合数学.某一天她解决了这样一个问题:“给一个网格图,其中某些格子有财宝.每次从左上角出发,只能往右或下走.问至少要走几次才能把财宝全部捡完 ...
- 2019 wannafly winter camp day5-8代码库
目录 day5 5H div2 Nested Tree (树形dp) 5F div2 Kropki (状压dp) 5J div1 Special Judge (计算几何) 5I div1 Sortin ...
- NYOJ 301 递推求值
第一次写博客,拿个矩阵快速幂练练手吧. 首先什么是快速幂,快速幂是让复杂度由线性降为log n的算法,比如8^1024次方暴力要算1024次,但是矩阵快速幂只算10次就好. 此题只不过是把快速幂的底数 ...
- 关于Python中函数的使用
函数的概念 # 概念 # 写了一段代码实现了某个小功能; 然后把这些代码集中到一块, 起一个名字; 下一次就可以根据这个名字再次使用这个代码块, 这就是函数 # 作用 # 方便代码的重用 # 分解任务 ...
- unzip失败,unzip:报错End-of-central-directory signature not found、scp:报错no space left on device
文章目录 问题 解决 拓展 问题 通过rz命令传本地文件到本地服务器,失败. 通过scp命令尝试报错: no space left on device 意思是目的机器内存不够用了,但是传过去了,但是没 ...
- vim与ctags/cscope的完美结合
1. 安装vim/ctags/cscope ctag 2. 在源码根目录下执行 sudo ctags -R . 会生成tags文件,里面包含着整个源码目录下的符号信息. 3. 直接到达某个符号(比 ...
- 1085 Perfect Sequence (25 分)
Given a sequence of positive integers and another positive integer p. The sequence is said to be a p ...
- centos_mysql踩坑
1 mysql安装 a: #wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm b:rpm -ivh mysq ...
- Servlet.init() for servlet [springmvc] threw exception
项目还没开始做,就碰到那么多问题.. 报错一:/oa/news/%E6%A0%8F%E7%9B%AE%E7%AE%A1%E7%90%86.jsp 1.一开始是jsp的页面名称为中文,改了 2.接着仍然 ...
- 关于scroll实现侧边导航栏
需求为一个简单的scroll效果,侧边选项卡跟随屏幕向下拖动变颜色的.点击侧边选项卡,跳转到相应模块. 索性上网找了一下类似的效果.附带源码地址 https://blog.csdn.net/drea ...