hdu 4994 前后有序Nim游戏
http://acm.hdu.edu.cn/showproblem.php?pid=4994
Nim游戏变成从前往后有序的,谁是winner?
如果当前堆数目为1,玩家没有选择,只能取走。遇到到不为1的堆,则当前回合行动者可以选择下次选择的先后手。考虑之后的状态为S,如果S为必败态,则玩家可以取完当前堆,下轮变后手,否则,将当前堆数目变为1,下轮先手。
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL;
int n,x; int main() {
int _;RD(_);while(_--){
RD(n);
int ans = 0,x,flag = 0;
for(int i = 0;i < n;++i){
RD(x);
if(x > 1)
flag = 1;
if(!flag)
ans++;
}
if(flag){
if(ans&1)
puts("No");
else
puts("Yes");
}
else{
if(ans&1)
puts("Yes");
else
puts("No");
}
}
return 0;
}
hdu 4994 前后有序Nim游戏的更多相关文章
- HDU - 4994 Revenge of Nim (取石子游戏)
Problem Description Nim is a mathematical game of strategy in which two players take turns removing ...
- HDU 5465 Clarke and puzzle Nim游戏+二维树状数组
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle Accepts: 42 Submissions: 26 ...
- HDU 1850 Being a Good Boy in Spring Festival(博弈·Nim游戏)
Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32 ...
- HDU 5795 A Simple Nim(简单Nim)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- NIM游戏,NIM游戏变形,威佐夫博弈以及巴什博奕总结
NIM游戏,NIM游戏变形,威佐夫博弈以及巴什博奕总结 经典NIM游戏: 一共有N堆石子,编号1..n,第i堆中有个a[i]个石子. 每一次操作Alice和Bob可以从任意一堆石子中取出任意数量的石子 ...
- HDU 4994 博弈。
F - 6 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- HDU 5795 A Simple Nim 打表求SG函数的规律
A Simple Nim Problem Description Two players take turns picking candies from n heaps,the player wh ...
- Nim游戏
目前有3堆石子,每堆石子个数也是任意的,双方轮流从中取出石子,规则如下:1)每一步应取走至少一枚石子:每一步只能从某一堆中取走部分或全部石子:2)如果谁不能取谁就失败. Bouton定理: 必败状态当 ...
- BZOJ 3105 [CQOI2013]新Nim游戏 ——线性基
[题目分析] 神奇的题目,两人都可以第一次取走足够多堆的石子. nim游戏的规则是,如果异或和为0,那么就先手必输,否则先手有必胜策略. 所以只需要剩下一群异或和为0就可以了. 先排序,线性基扫一遍即 ...
随机推荐
- 面向对象三大特性一一多态(polymorphism)
package com.bjsxt.oop.polymorphism; public class Animal { public void voice(){ System.out.println(&q ...
- Eclipse安装教程
Eclipse安装教程 (Win7_64bit + Eclipse_64bit + JDK_8u131_64bit + python2.7.8 + PyDev5.7.0插件) 适用操作系统:W ...
- js 触发 change 事件
首先,请各位包涵,我本人对 JS 不是很熟,不知道"触发change事件"和"触发onchange事件"哪个更加合适.有园友知道的麻烦指出,先行谢过. 起因是这 ...
- where T:new() 是什么意思
经常看到方法后面加where T:new() ,下面来解释下 比如如下这个方法 protected static T CreateNewInstance<T>() where T : ...
- java基础六 [异常处理](阅读Head First Java记录)
在程序运行时,我们不能保证所有服务和方法都是正确的,如果发生问题报错会导致程序崩溃,所以需要对一些可以预见的错误进行异常处理,通过throw去抛出一个异常,然后用try..catch..将要执行的该方 ...
- Python3 input() 函数
Python3 input() 函数 Python3 内置函数 Python3.x 中 input() 函数接受一个标准输入数据,返回为 string 类型. 注意:在 Python3.x 中 ra ...
- ECMAScript5新特性之获取对象特有的属性
'use strict'; // 父类 function Fruit(){ } Fruit.prototype.name = '水果'; // 子类 function Apple(desc){ thi ...
- Appium原理初步--Android自动化测试学习历程
章节:自动化基础篇——Appium原理初步(第七讲) 本期关键词: Appium.跨语言跨平台.Bootstrap 主要讲解内容及笔记: 一.what is appium 一种封装了uiautomat ...
- Repeater嵌套Repeater
<asp:Repeater ID="rptXiaoLei" runat="server" OnItemDataBound="rptXiaoLei ...
- 一种管理z-index属性的方案
原文在这里:http://www.smashingmagazine.com/2014/06/12/sassy-z-index-management-for-complex-layouts/ 核心思想是 ...