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
题解:反NIM博弈板题;(anti-NIM博弈见前面博弈总结)知道:先手必胜的状态有两种: 1:全是一个,且ans=0;
2 : 不全是一个,且ans!=0;(ans为所有的异或和);
其他的情况均为先手必败;
参考代码:
#include<bits/stdc++.h>
using namespace std;
int T,n,x,ans,cnt;
int main()
{
scanf("%d",&T);
for(int cas=;cas<=T;cas++)
{
scanf("%d",&n);
cnt=ans=;
for(int i=;i<=n;++i)
{
scanf("%d",&x);
if(x==) cnt++;
ans^=x;
}
if(cnt==n)
{
if(ans==) printf("Case %d: Alice\n",cas);
else printf("Case %d: Bob\n",cas);
}
else
{
if(ans) printf("Case %d: Alice\n",cas);
else printf("Case %d: Bob\n",cas);
}
} return ;
}
LightOJ 1253 Misere NIM(反NIM博弈)的更多相关文章
- Light OJ 1253 Misere Nim (尼姆博弈(2))
LightOJ1253 :Misere Nim 时间限制:1000MS 内存限制:32768KByte 64位IO格式:%lld & %llu 描述 Alice and Bob ar ...
- hdu2509Be the Winner(反nim博弈)
Be the Winner Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu1907John(反nim博弈)
John Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submis ...
- BZOJ_1022_[SHOI2008]_小约翰的游戏John_(博弈论_反Nim游戏)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1022 反Nim游戏裸题.详见论文<组合游戏略述——浅谈SG游戏的若干拓展及变形>. ...
- BZOJ 1022 / P4279 Luogu [SHOI2008]小约翰的游戏 (反Nim游戏) (Anti-SG)
题意 反Nim游戏,两人轮流选一堆石子拿,拿到最后一个的输.问先手是否必胜. 分析 怎么说,分类讨论? 情形1:首先考虑最简单的情况,所有石子数都为1.那么奇数堆石子为必败,偶数为必胜 情形2:然后考 ...
- 两类特殊的Nim游戏:Nim-K游戏与反Nim游戏
Nim-K游戏 描述 有\(n\)堆石子,每次可从\(k\)堆石子中拿走任意数量的石子. 两个人轮流拿,谁不能拿谁输. 先手必胜条件 把\(n\)堆石子的石子数用二进制表示,统计每一个二进制位上\(1 ...
- nyoj888 取石子(九) 反Nimm博弈
这题就是反Nimm博弈--分析见反Nimm博弈 AC代码 #include <cstdio> #include <cmath> #include <algorithm&g ...
- nim博弈 LightOJ - 1253
主要是写一下nim博弈的理解,这个题有点奇怪,不知道为什么判断奇偶性,如果有大佬知道还请讲解一下. //nim博弈 //a[0]~a[i] 异或结果为k 若k=0 则为平衡态 否则为非平衡态 //平衡 ...
- LightOJ - 1247 Matrix Game (Nim博弈)题解
题意: 给一个矩阵,每一次一个玩家可以从任意一行中选任意数量的格子并从中拿石头(但最后总数要大于等于1),问你谁赢 思路: 一开始以为只能一行拿一个... 将每一行石子数相加就转化为经典的Nim博弈 ...
随机推荐
- 前端Leader你应该知道的NPM包管理机制
npm install 命令 首先总结下npm 安装一个模块包的常用命令. /* 模块依赖会写入 dependencies 节点 */ npm install moduleName npm insta ...
- 解决WordPress不能发邮件,WordPress 无法发送邮件
解决WordPress不能发邮件,WordPress 无法发送邮件,不得不说WordPress这个问题真的很烦人,研究了一下午发现不能发邮件的问题无非以下几种! 1.系统本身问题,这个直接装个插件即可 ...
- 启动Spring Tool Suite 4时出现 could not find tools.jar spring boot live hovers....弹窗
第一步:检查一下STS启动时的加载环境 Help —› About Spring Tool Suite 4 —› Installation Details —› Configuration 本人已经 ...
- spark集群搭建(三台虚拟机)——spark集群搭建(5)
!!!该系列使用三台虚拟机搭建一个完整的spark集群,集群环境如下: virtualBox5.2.Ubuntu14.04.securecrt7.3.6_x64英文版(连接虚拟机) jdk1.7.0. ...
- 0x8000FFFF 错误的解决方式
问题描述: 在F盘新建文件夹或文件的时候提示0x8000FFFF灾难性错误: 解决方法: 1.在F盘的位置,右击选择属性 2.在弹出的窗口中选择工具,点击检查 3.根据系统提示进行响应的驱动扫描与修复 ...
- Java的String类详解
Java的String类 String类是除了Java的基本类型之外用的最多的类, 甚至用的比基本类型还多. 同样jdk中对Java类也有很多的优化 类的定义 public final class S ...
- Grid表格的js触发事件
没怎么接触过Grid插件: 解决的问题是:点击Grid表行里的内容触发js方法弹出模态框,用以显示选中内容的详细信息. 思路:给准备要触发的列加上一个css属性,通过这个css属性来获取元素并触发js ...
- ZeroC ICE的远程调用框架 AMI与AMD -Why?
在Ice有两种异步使用的方式,AMI和AMD.AMI是异步方法调用,AMD是异步方法调度(分派).前者用在代理端,后者用在饲服实现端. AMI其实就是在代理端,使用Future机制进行异步调用,而不阻 ...
- python 学习路程(一)
好早之前就一直想学python,可是一直没有系统的学习过,给自己立个flag,从今天开始一步步掌握python的用法: python是一种脚本形式的语言,据说是面向废程序员学习开发使用的,我觉得很适合 ...
- HDFS之DataNode
DataNode工作机制 1)一个数据块在datanode上以文件形式存储在磁盘上,包括两个文件,一个是数据本身,一个是元数据包括数据块的长度,块数据的校验和,以及时间戳. 2)DataNode启动后 ...