poj 3537 Crosses and Crosses 博弈论
思路:每次画X之后都会形成2个子游戏,即i-3和n-i-2.
代码如下:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
int sg[];
int getsg(int n)
{
if(n<=) return ;
if(sg[n]>=) return sg[n];
bool vis[]={};
for(int i=;i<=n;i++){
vis[getsg(n-i-)^getsg(i-)]=;
}
int i=;
while(vis[i]) i++;
return sg[n]=i;
}
int main()
{
int n;
memset(sg,-,sizeof(sg));
while(scanf("%d",&n)!=EOF){
puts(getsg(n)?"":"");
}
return ;
}
poj 3537 Crosses and Crosses 博弈论的更多相关文章
- poj 3537 Crosses and Crosses 博弈论之grundy值
题意: 给1*n的格子,轮流在上面叉叉,最先画得3个连续叉叉的赢.问先手必胜还是必败. 分析: 求状态的grundy值(也就是sg值),详细怎么求详见代码.为什么这么求要自己想的,仅仅可意会(别人都说 ...
- 【POJ】【3537】Crosses and Crosses
博弈论 相当于放了x的位置,左右4格都不能再放x了,谁无处可放就输. n<=2000 直接枚举后继状态,暴力求SG函数即可. 例: 0000000->x..0000 / .x..000 / ...
- POJ 3537 Crosses and Crosses
Crosses and Crosses Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 2237 Accepted: 821 Ca ...
- POJ 3537 Crosses and Crosses (NEERC)
Crosses and Crosses Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 4 ...
- poj 3575 Crosses and Crosses(SG函数)
Crosses and Crosses Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 3063 Accepted: 11 ...
- [poj3537]Crosses and Crosses_博弈论
Crosses and Crosses poj-3537 题目大意:给定一个1*n的网格,每次往格子内填一个$\times$,连续的三个即可获胜. 注释:$1\le n\le 2000$. 想法:我们 ...
- POJ 3537 multi-sg 暴力求SG
长为n的一列格子,轮流放同种棋子,率先使棋子连成3个者胜. 可以发现每次放一个棋子后,后手都不能放在[x-2,x+2]这个区间,那么相当于每次放棋将游戏分成了两个,不能放棋者败. 暴力求SG即可 /* ...
- POJ.1067 取石子游戏 (博弈论 威佐夫博弈)
POJ.1067 取石子游戏 (博弈论 威佐夫博弈) 题意分析 简单的威佐夫博弈 博弈论快速入门 代码总览 #include <cstdio> #include <cmath> ...
- [poj 3537]Crosses and Crosses(博弈论)
题目:http://poj.org/problem?id=3537 题意:给你n个格子,两个人依次在n个格子的任意空位置画"X",谁如果画了一个后,3个X连在了一起,那么那个人就获 ...
随机推荐
- linux下安装protobuf教程+示例(详细)
(.pb.h:9:42: fatal error: google/protobuf/stubs/common.h: No such file or directory 看这个就应该知道是没有找到头文件 ...
- require.js的用法
我采用的是一个非常流行的库require.js. 一.为什么要用require.js? 最早的时候,所有Javascript代码都写在一个文件里面,只要加载这一个文件就够了.后来,代码越来越多,一个文 ...
- TableViewCell Swipe to Delete and More Button(like mail app in iOS7 or later)
在iOS7系统的Mail App中TableViewCell的一个功能让我们做TableView的比较羡慕,就是滑动cell,右边出现了两个按钮,如下: 网上在github上有很多大牛用custom ...
- liferay7中如何Hiding the default Success Message
下面介绍如何把在Liferay 7中如何把action执行成功之后的信息不显示,因为宝宝有需要,就去查了相关源码和资料. 如果想要某个portlet不显示执行成功的信息,在doProcessActio ...
- springmvc返回jsp源代码解决办法
url-pattern问题 spring用到forward("/WEB-INF/jsp/*.jsp")而forward当然是又要经过web.xml的映射的,然后,在URL匹配时, ...
- 【Sort Colors】cpp
题目: Given an array with n objects colored red, white or blue, sort them so that objects of the same ...
- The income statement
The income statement measures performance over some period of time,usually a quarter or a year.The ...
- 《JavaScript高级程序设计》第3章 基本概念
3.4 数据类型 3.4.1 typeof操作符 var message = 'some string'; console.log(typeof message); // 'string' conso ...
- Hibernate中查询数据转成VO对象及注意问题
大家都可能会遇到,在用json传输数据时,很多字段是来自不同的表数据,需要我们进行封装数据. hibernate提供这么一个方法用来直接封装查询属性: query.setResultTransform ...
- GS初始化
开启GameServer模式 init函数,现在看看这个大函数干什么的 //这个init也是GameServerUI里面调的,这个线程其实就做了一些初始化的工作,其实这里面没有什么主不主线程,都是在一 ...