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 事件代理及应用
事件代理又叫事件委托在前端发开中实际是非常有用的,说事件代理之前我们先说说事件绑定 <p onclick="test()" ></p> function t ...
- VB.NET Shared(共享)和 Static(静态)关键字的区别
共享成员(Shared): VB.NET现在是支持真正的面向对象编程,可以继承.使用多态.共享成员 和静态成员. 共享成员就是在所有类和所定义派生类的实例之间共享的方法.属 性.字段和事件.所有使用类 ...
- Linux命令备忘录
1.tar命令 解压tar.gz格式压缩包:tar zxvf xxx.tar.gz 解压tar.bz2格式压缩包:tar jxvf xxx.tar.bz2 压缩为tar.gz格式压缩包:tar zcv ...
- jQuery EasyUI API 中文文档 - 面板(Panel)
Panel 面板 用$.fn.panel.defaults重写defaults. 用法示例 创建Panel 1. 经由标记创建Panel 从标记创建Panel更容易.把 'easyui-panel ...
- Mybatis.net与MVC入门配置及联合查询动态SQL拼接和简单事务
第一次学习Mybatis.net,在博客园也找到好多资料,但是在配置成功之后也遇到了一些问题,尤其是在动态SQl拼接时候,这里把遇到的问题还有自己写的一个Demo贴出来,希望能帮到新手,有不适合的地方 ...
- WeUI
从WeUI学习到的知识点 WeUI是微信Web服务开发的UI套件, 目前包含12个模块 (Button, Cell, Toast, Dialog, Progress, Msg, Article, ...
- JAVA笔记1-00
package chapter1; public class Demo1 { public static void main(String[] args) { System.out.println(& ...
- 【配置】电信华为HG8245 无线路由器配置 有贴图
引子:家里的电信无线路由器连接之后无法直接上上网,只能再次通过PPPoe方式拨号上网.经过网上查询和一番折腾之后,整理攻略如下. 1. 用超级用户登录192.168.1.1(默认密码) 用 ...
- PIMPL设计模式的理解和使用
以下两段不同程序的比较 //file a.h #include "a.h" #include “ b.h” class A{ void Fun(); B b; } //file: ...
- PDM使用问题总结
1.连接postgres生成pdm 直接连postgres数据库生成的可以生成表名,但表结构为空,不知为何,后来直接用生成数据库sql脚本后转成pdm成功.但是列注释没有了. 2.sql语句生成的pd ...