hdu 2509 Be the Winner 博弈
有n堆苹果, 对于其中的每一堆的x个苹果, 它是放在一条线上的。 你每次可以对一堆苹果进行操作, 可以取y个, 1<=y<=x。 然后如果你是取的一条线上中间的苹果, 那么这一堆苹果将会变成两堆。 问你先手是否必胜。
简单的打一个sg表就可以了。 注意特判全都是1的情况。
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef complex <double> cmx;
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
int sg[];
int mex(int x)
{
if(~sg[x])
return sg[x];
bool vis[];
memset(vis, false, sizeof(vis));
for(int i = ; i <= x; i++) {
for(int j = ; j <= x-i; j++) {
vis[mex(j)^mex(x-i-j)] = ;
}
}
for(int i = ; ; i++)
if(!vis[i])
return sg[x] = i;
}
int main()
{
int n, x;
mem1(sg);
for(int i = ; i <= ; i++) {
mex(i);
}
while(cin>>n) {
int ans = , flag = ;
for(int i = ; i < n; i++) {
scanf("%d", &x);
if(x > )
flag = ;
ans ^= sg[x];
}
if(!ans) {
if(flag)
puts("No");
else
puts("Yes");
} else {
if(flag)
puts("Yes");
else
puts("No");
}
}
return ;
}
hdu 2509 Be the Winner 博弈的更多相关文章
- hdu 1907 John&& hdu 2509 Be the Winner(基础nim博弈)
Problem Description Little John is playing very funny game with his younger brother. There is one bi ...
- HDU 2509 Be the Winner nim博弈变形
Be the Winner Problem Description Let's consider m apples divided into n groups. Each group contai ...
- (step8.2.2)hdu 2509(Be the Winner——简单博弈)
题目大意:输入一个整数n,表示火柴堆数(原题其实指的是苹果堆数,但是为了尽量与模板保持一致,所以在这里理解为火柴堆数....其实理解为什么都没关系, 重要的是,理解就行....).在接下来的一行中,有 ...
- HDU 2509 Be the Winner(取火柴博弈2)
传送门 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int ...
- hdu 2509 Be the Winner(anti nim)
Be the Winner Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu 2509 Be the Winner 博弈论
博弈论水题!!! 代码如下: #include<stdio.h> #include<iostream> using namespace std; int main(){ int ...
- HDU 2509 Nim博弈变形
1.HDU 2509 2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...
- HDU 2509 基础Anti-SG NIM
如果我们规定当局面中所有的单一游戏的SG值为0时,游戏结束,则先手必胜当且仅当:(1)游戏的SG!=0 && 存在单一游戏的SG>1:(2)游戏的SG==0 && ...
- HDU 1524 树上无环博弈 暴力SG
一个拓扑结构的图,给定n个棋的位置,每次可以沿边走,不能操作者输. 已经给出了拓扑图了,对于每个棋子找一遍SG最后SG和就行了. /** @Date : 2017-10-13 20:08:45 * @ ...
随机推荐
- JavaScript 原型链的一点想法
JavaScript借鉴了许多语言的特点:例如语法类Java.函数借鉴Scheme.原型继承借鉴自Self.正则表达式借鉴于Perl.(DC Javascript:语言精粹). 首先,每个J ...
- VS 2013驱动开发 + Windbg + VM双机调试(亲测+详解)
------------VS 2013驱动开发 + Windbg + VM双机调试(亲测+详解)------------- WIN10已上线,随之而来的是VS2015:微软在 "WDK760 ...
- JavaScript事件属性绑定带参数的函数
JavaScript中在对事件进行绑定的时候,往往是element.onclick=event;这种形式,这样使用的话则会出现无法传参数.因此我们可以使用function(){}匿名函数将事件包含其中 ...
- apache AH01630: client denied by server configuration错误解决方法
今天本来是想要在自己本地搭建一个wamp环境用来做一些代码的测试和框架的学习. 鉴于目前工作的时候用到了php5.5,所以就用了wamp-server V2.5版本,安装完成之后配置虚拟主机一直出现4 ...
- Oracle EBS-SQL (PO-18):检查工作台下达的PR在系统找不到.sql
select * From apps.po_requisitions_interface_all---------------------------------------------------- ...
- fragment低版本
http://bbs.csdn.net/topics/390271980 Fragment框架开发东西确实很方便,但是恼人的是从4.0才开始支持.以前的版本必须用兼容模式开发,本人在网上找了大量资料, ...
- Rule Or WorkFlow
The main value of a Workflow engine is that it makes it possible to customize the flows through some ...
- JVM 看不到某些异常的stacktrace问题(转)
在java 1.5的release notes里面可以看到这样一句话: The compiler in the server VM now provides correct stack backtra ...
- 你真的用上keepalive了吗
转自http://qa.blog.163.com/blog/static/19014700220134771052763/ Keep-Alive即俗称的长连接,使客户端到服务端建立的连接持续有效,当对 ...
- NODE.JS安装配置