poj 3537 Crosses and Crosses 博弈论之grundy值
题意:
给1*n的格子,轮流在上面叉叉,最先画得3个连续叉叉的赢。问先手必胜还是必败。
分析:
求状态的grundy值(也就是sg值),详细怎么求详见代码。为什么这么求要自己想的,仅仅可意会(别人都说去看game theory,呵呵)。
代码:
//poj 3537
//sep9
#include <iostream>
#include <set>
using namespace std;
int grundy[2048];
int h[2048];
int get_grundy(int n)
{
if(n<0)
return 0;
if(grundy[n]!=-1)
return grundy[n];
int h[2048];
memset(h,0,sizeof(h));
for(int i=1;i<=n;++i){
int t=get_grundy(i-3)^get_grundy(n-i-2);
h[t]=1;
}
int i;
for(i=0;h[i];++i);
return grundy[n]=i;
}
int main()
{
int n;
memset(grundy,-1,sizeof(grundy));
grundy[0]=0,grundy[1]=1,grundy[2]=1,grundy[3]=1;
while(scanf("%d",&n)==1)
if(get_grundy(n)!=0)
puts("1");
else
puts("2");
return 0;
}
poj 3537 Crosses and Crosses 博弈论之grundy值的更多相关文章
- 【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$. 想法:我们 ...
- 博弈论:寻找先手必胜策略——Grundy值
选修了人工智能课程,老师布置了调研任务:Grundy,开始看了一些资料并没有看懂. 后来找到了一篇文,写的很棒,里面有好多博弈相关的问题与分析,分享出来给大家: http://endless.logd ...
- POJ 3537 multi-sg 暴力求SG
长为n的一列格子,轮流放同种棋子,率先使棋子连成3个者胜. 可以发现每次放一个棋子后,后手都不能放在[x-2,x+2]这个区间,那么相当于每次放棋将游戏分成了两个,不能放棋者败. 暴力求SG即可 /* ...
- POJ.1067 取石子游戏 (博弈论 威佐夫博弈)
POJ.1067 取石子游戏 (博弈论 威佐夫博弈) 题意分析 简单的威佐夫博弈 博弈论快速入门 代码总览 #include <cstdio> #include <cmath> ...
- 硬币游戏2&&Cutting Game——Grundy值
Grundy值 当前状态的Grundy值就是除任意一步所能转移到的状态的Grundy值以外的最小非负整数, 以硬币问题一为例,可写成: int init_grundy() { sg[] = ; ;i ...
随机推荐
- (3)C#工具箱-容器
容器特点:把控件放到容器里,移动容器控件也会跟着移动. 1.flowLayoutPanel(流布局控件) 放入控件后,会自动垂直或水平排列 拉长布局,控件自动跑到一行 2.GroupBox(组合框) ...
- Peak
A sequence of \(n\) integers \(a_1, a_2, \dots, a_n\) is called a peak, if and only if there exists ...
- js获取屏幕
js获取屏幕(设备)宽高 <script language="javascript"> var h = ""; h += " 网页可见区域 ...
- eclipse无法导入Android工程的解决办法
我以前在windows平台下写的android源代码无法通过import"existing project into workspace"导入到mac的eclipse中,直接搜不见 ...
- Bluetooth篇 开发实例之五 为什么无线信号(RSSI)是负值?
原文:http://www.cnblogs.com/lele/articles/2832885.html 为什么无线信号(RSSI)是负值 答:其实归根到底为什么接收的无线信号是负值,这样子是不是 ...
- Jenkins忘记密码的修复方法(Windows/Linux)
在jenkins的安装目录下,找到config.xml配置文件,删除以下节点: <useSecurity>true</useSecurity> <authorizatio ...
- SONY的一款Win8平板
今天看到了SONY新发布的一款x86的平板电脑: 铝合金的机身,分离的屏幕,非常漂亮.参数上还是很给力的,i5-4210/i7-4610的处理器,1920x1080的屏幕.4G的内存.9.9mm的厚度 ...
- MySQL 三节点企业版
https://promotion.aliyun.com/ntms/act/rds/mysqlenterprise.html
- 【java】java反射机制,动态获取对象的属性和对应的参数值,并属性按照字典序排序,Field.setAccessible()方法的说明【可用于微信支付 签名生成】
方法1:通过get()方法获取属性值 package com.sxd.test.controller; public class FirstCa{ private Integer num; priva ...
- Spring整合Hibernate的时候使用hibernate.cfg.xml
Spring整合Hibernate其实也就是把Hibernate的SessionFactory对象封装成:org.springframework.orm.hibernate3.LocalSession ...