POJ 3537 multi-sg 暴力求SG
长为n的一列格子,轮流放同种棋子,率先使棋子连成3个者胜。
可以发现每次放一个棋子后,后手都不能放在[x-2,x+2]这个区间,那么相当于每次放棋将游戏分成了两个,不能放棋者败。
暴力求SG即可
/** @Date : 2017-10-14 22:50:13
* @FileName: POJ 3537 multi-sg 暴力SG.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <queue>
#include <math.h>
//#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; int sg[N]; int dfs(int x)
{
if(x < 0)
return 0;
if(sg[x] != -1)
return sg[x];
int vis[2010];
MMF(vis);
for(int i = 1; i <= x; i++)
vis[dfs(i - 3) ^ dfs(x - i - 2)] = 1;
for(int i = 0; ;i++)
if(!vis[i])
return sg[x] = i;
return sg[x];
} int main()
{
int n;
while(cin >> n)
{
MMG(sg);
int ans = dfs(n);
printf("%d\n", ans?1:2);
}
return 0;
}
POJ 3537 multi-sg 暴力求SG的更多相关文章
- POJ 3537 Crosses and Crosses(SG/还未想完全通的一道SG)
题目链接 #include<iostream> #include<cstdio> #include<cstring> using namespace std; ]; ...
- poj 3537 Crosses and Crosses (SG)
题意: 1 × n 个格子,每人每次选一个格子打上叉(不得重复),如果一个人画完叉后出现了连续的三个叉,则此人胜. 给n,判断先手胜还是先手败. 思路: 假设选择画叉的位置是i,则对方只能在前[1,i ...
- POJ 3537 Crosses and Crosses(sg博弈)
题目:在1*n 的棋盘里面,A和B都在里面画叉 , 如果谁可以画了一个叉后,可以连成3个叉,那谁胜利 : 分析: 首先考虑如果我在玩游戏,我最希望对手可以画出-x-x or -xx- , 这种 ...
- POJ 2425 A Chess Game#树形SG
http://poj.org/problem?id=2425 #include<iostream> #include<cstdio> #include<cstring&g ...
- POJ 2311 Cutting Game(二维SG+Multi-Nim)
Cutting Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4798 Accepted: 1756 Desc ...
- poj 3575 Crosses and Crosses(SG函数)
Crosses and Crosses Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 3063 Accepted: 11 ...
- poj 2425 A Chess Game(SG函数)
A Chess Game Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 3551 Accepted: 1440 Desc ...
- poj 3710 Christmas Game【博弈论+SG】
也就是转换到树形删边游戏,详见 https://wenku.baidu.com/view/25540742a8956bec0975e3a8.html #include<iostream> ...
- POJ 3537:Crosses and Crosses(Multi-Nim)
[题目链接] http://poj.org/problem?id=3537 [题目大意] 在一个1*n的方格纸上下棋,谁先连三子谁就赢了,问必胜的是谁. [题解] 我们发现对于一个n规模的游戏.在i位 ...
随机推荐
- kafka0.8--0.11各个版本特性预览介绍
kafka-0.8.2 新特性 producer不再区分同步(sync)和异步方式(async),所有的请求以异步方式发送,这样提升了客户端效率.producer请求会返回一个应答对象,包括偏移量或者 ...
- Jq_网站顶部定时折叠广告
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><titl ...
- 【原】python3.7 无法pip安装提示ssl错误解决方案
问题 pip is configured with locations that require TLS/SSL, however the ssl module in Python is not av ...
- GTK学习笔记————创建窗口
创建gtk1.c文件 代码 #include <gtk/gtk.h> int main (int argc, char *argv[]) { GtkWidget *window; gtk_ ...
- OpenMPI源码剖析:网络通信原理(二) 如何选择网络协议?
因为比较常用的是 TCP 协议,所以在 opal/mca/btl/tcp/btl_tcp.h 头文件中找到对应的 struct mca_btl_tcp_component_t { mca_btl_ba ...
- CSAPP lab2 二进制拆弹 binary bombs phase_6
给出对应于7个阶段的7篇博客 phase_1 https://www.cnblogs.com/wkfvawl/p/10632044.htmlphase_2 https://www.cnblogs. ...
- Day Five
站立式会议 站立式会议内容总结 442 今天:编写具体计划的界面 遇到的问题:相对布局.绝对布局理解不够深刻 明天:完成设定计划时间的功能 331 今天:添加书籍/计划按钮,添加书籍时有一个文件选择 ...
- 03-java学习-基本数据类型-运算符-键盘接收用户输入
java的八大基本数据类型: 类型转换的基本原则: java整数的默认类型是int,小数的默认类型是double 运算符: 算术运算符.连接.赋值.关系.逻辑.三目运算符等…… 键盘接收用户输入: j ...
- spring @component的作用
该文转载自:http://tomfish88.iteye.com/blog/1497557 1.@controller 控制器(注入服务) 2.@service 服务(注入dao) 3.@reposi ...
- ELK Stack (2) —— ELK + Redis收集Nginx日志
ELK Stack (2) -- ELK + Redis收集Nginx日志 摘要 使用Elasticsearch.Logstash.Kibana与Redis(作为缓冲区)对Nginx日志进行收集 版本 ...