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博弈 ...
随机推荐
- 《计算机网络 自顶向下方法》 第3章 运输层 Part2
待补充完善 TCP 相关基本点 1.面向连接 两个不同主机上的进程在通过 TCP 进行通信之前,必须先通过三次握手来建立 TCP 连接 2.全双工服务 即,如果一台主机上的进程 A 与另一台主机上的进 ...
- docker swarm 过滤器affinity 限制副本不会出现在同一个节点上
affinity:container!=容器服务名称(可以是正则) 举个例子:stack_ds.yaml # cat stack_dsc.yaml version: '3.0' services: t ...
- Material for oauth 2
oauth 2 in 8 steps: https://knpuniversity.com/screencast/oauth Live demo of oauth 2 (with server im ...
- T-SQL Part IV: ORDER BY
ORDER BY 返回一个Cursor,并不返回结果集.而试图将Cursor作为输入将产生了错误. 所以,下列的SQL语句将产生错误: SELECT VerID, IsComplete VerID, ...
- django_4数据库3——admin
生成admin界面 1.setting.py中,保证'django.contrib.admin',应用打开,django1.11默认打开的 2.url.py中的admin默认时打开的 3.对model ...
- vuejs学习之新的components组件挂载
暂时写个目录,内容待完善,主要是记录我的学习过程,方便以后复习
- Web Deploy远程发布
前言 我们在使用VS开发.net网站的时候,部署时可能会遇到缺少dll的问题,每次都远程桌面登陆,然后拷贝过去,太麻烦了.我们可以使用Web Deploy这个远程部署工具,不仅部署容易了,也方便进行迭 ...
- Protues7.8仿真软件有中文路径无法正常运行怎么办?
Protues7.8是一款功能强大的单片机仿真软件,在我们的学习生活中经常会用的到,在装软件时明明已经装好了,却不能报错跳出两行红字,让人心痛. 一般都是因为账户名字是中文的问题,这个软件对中文不兼容 ...
- Linux -- 进程间通信之信号量
基本概念简述 多个线程同时访问一个共享数据,很可能造成恶劣的后果:为了保证数据访问资源的正确性和安全性,需要对线程进行"同步" (Linux下所有的执行实体都称为任务(task), ...
- 请求库urllib和urllib3
# coding=utf-8 # urllib """ 使用python的urllib库去模拟浏览器请求网页,常用内容如下: urllib.request 发送HTTP请 ...