题目链接

有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 博弈的更多相关文章

  1. 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 ...

  2. HDU 2509 Be the Winner nim博弈变形

    Be the Winner Problem Description   Let's consider m apples divided into n groups. Each group contai ...

  3. (step8.2.2)hdu 2509(Be the Winner——简单博弈)

    题目大意:输入一个整数n,表示火柴堆数(原题其实指的是苹果堆数,但是为了尽量与模板保持一致,所以在这里理解为火柴堆数....其实理解为什么都没关系, 重要的是,理解就行....).在接下来的一行中,有 ...

  4. HDU 2509 Be the Winner(取火柴博弈2)

    传送门 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int ...

  5. 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 ...

  6. hdu 2509 Be the Winner 博弈论

    博弈论水题!!! 代码如下: #include<stdio.h> #include<iostream> using namespace std; int main(){ int ...

  7. HDU 2509 Nim博弈变形

    1.HDU 2509  2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...

  8. HDU 2509 基础Anti-SG NIM

    如果我们规定当局面中所有的单一游戏的SG值为0时,游戏结束,则先手必胜当且仅当:(1)游戏的SG!=0 && 存在单一游戏的SG>1:(2)游戏的SG==0  && ...

  9. HDU 1524 树上无环博弈 暴力SG

    一个拓扑结构的图,给定n个棋的位置,每次可以沿边走,不能操作者输. 已经给出了拓扑图了,对于每个棋子找一遍SG最后SG和就行了. /** @Date : 2017-10-13 20:08:45 * @ ...

随机推荐

  1. mysql数据备份和还原命令

    mysql数据库备份和还原   备份MySQL数据库的命令 mysqldump -hhostname -uusername -ppassword databasename > backupfil ...

  2. windows系统部署discuz并和javaweb账号连通同步

    一.Discuz安装说明 1.安装wamp集成环境 (1)下载wampserver集成环境 网址:(http://wampserver-64bit.en.softonic.com)或百度搜索下载 (2 ...

  3. JS delete 用法(删除对象属性及变量)

    1,对象属性删除 function fun(){ this.name = 'mm'; } var obj = new fun(); console.log(obj.name);//mm delete ...

  4. yii2不用composer使用redis

    1.下载redis https://github.com/yiisoft/yii2-redis 2.下载解压放到 basic\vendor\yiisoft\yii2-redis 3.编辑文件: bas ...

  5. Sphinx Makefile

    # Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPT ...

  6. Objective-C实现计算你写了多少行代码

    #import <Foundation/Foundation.h> NSInteger codeLineCount(NSString *path) { //1.获取文件管理者,这是一个单例 ...

  7. UVA 10129 Play on Words

    欧拉回路 以字母为结点,单词为边:注意两个相同的单词表示两条边. 并查集判断是否连通,出度,入度判断是否是欧拉回路 #include <iostream> #include <cst ...

  8. Azure上如何在Linux下挂载数据磁盘

    [原文首次发表于51cto http://cloudapps.blog.51cto.com/3136598/1653672] 在Azure上创建了虚拟机之后,我们在一些情况下会需要添加更多的数据磁盘来 ...

  9. Android_NFC_开发介绍

    API概览 Android.nfc 和android.nfc.tech 为android 处理nfc的java 包. 1.Android.nfc package包含顶层类用来与本地NFC适配器交互. ...

  10. 要熟悉QT的所有类和元类系统,当然还有qmake

    http://doc.qt.io/qt-5/classes.html http://doc.qt.io/qt-5/gettingstarted.html http://doc.qt.io/qt-5/q ...