poj1067-取石子游戏-wythoff博弈
打表找规律失败,搜了一下原来是wythoff博弈
/*--------------------------------------------------------------------------------------*/ #include <algorithm>
#include <iostream>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map> //debug function for a N*M array
#define debug_map(N,M,G) printf("\n");for(int i=0;i<(N);i++)\
{for(int j=;j<(M);j++){\
printf("%d",G[i][j]);}printf("\n");}
//debug function for int,float,double,etc.
#define debug_var(X) cout<<#X"="<<X<<endl;
#define LL long long
const int INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-;
/*--------------------------------------------------------------------------------------*/
using namespace std; int N,M,T;
int mem[][] = {};
const double q = (+sqrt(5.0)) / 2.0; void display(int x)
{
if(x==) return ;
display(x>>);
putchar((x&) + '');
} int sg(int a,int b)
{
if(mem[a][b] != -) return mem[a][b];
if(a == && b == )return ;
set<int> st ;
for(int i=;i<=a;i++)
{
st.insert(sg(a-i,b));
}
for(int i=;i<=b;i++)
{
st.insert(sg(a,b-i));
}
for(int i=;i<=min(a,b);i++)
{
st.insert(sg(a-i,b-i));
}
int g = ;
while(st.find(g) != st.end()) g++;
return mem[a][b] = g;
} int Wythoff(int a,int b)
{
if( a > b) swap(a,b);
int k = b - a;
if(a == (int)(k*q)) return ;
else return ;
} int main()
{
int a,b;
while(~scanf("%d%d",&a,&b))
{
printf("%d\n",Wythoff(a,b));
}
}
poj1067-取石子游戏-wythoff博弈的更多相关文章
- POJ-1067取石子游戏,威佐夫博弈范例题/NYOJ-161,主要在于这个黄金公式~~
取石子游戏 Time Limit: 1000MS Memory Limit: 10000K Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取 ...
- HDU 2516 取石子游戏(FIB博弈)
取石子游戏 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- 取石子游戏 BZOJ1874 博弈
小H和小Z正在玩一个取石子游戏. 取石子游戏的规则是这样的,每个人每次可以从一堆石子中取出若干个石子, 每次取石子的个数有限制,谁不能取石子时就会输掉游戏. 小H先进行操作,他想问你他是否有必胜策略, ...
- 【BZOJ1413】取石子游戏(博弈,区间DP)
题意:在研究过Nim游戏及各种变种之后,Orez又发现了一种全新的取石子游戏,这个游戏是这样的: 有n堆石子,将这n堆石子摆成一排.游戏由两个人进行,两人轮流操作,每次操作者都可以从最左或最右的一堆中 ...
- hdu 2516 取石子游戏 (Fibonacci博弈)
取石子游戏 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- POJ1067 取石子游戏 威佐夫博弈 博弈论
http://poj.org/problem?id=1067 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可 ...
- POJ1067 取石子游戏
Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...
- poj 1067 取石子游戏 (威佐夫博弈)
取石子游戏 http://poj.org/problem?id=1067 Time Limit: 1000MS Memory Limit: 10000K Description 有两堆 ...
- 「LuoguP2252」 取石子游戏(威佐夫博弈
[P2252]取石子游戏 - 洛谷 题目背景 无 题目描述 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以 ...
随机推荐
- Linux网络编程&内核学习
c语言: 基础篇 1.<写给大家看的C语言书(第2版)> 原书名: Absolute Beginner's Guide to C (2nd Edition) 原出版社: Sams 作者: ...
- PHP错误日志控制(display_errors和error_reporting)
display_errors和error_reporting是php程序调试过程中两个非常重要的参数,下面就来介绍一下这两个错误日志的配置如何开启和关闭: 我们知道在产品的生产环境肯定是不能够显示错误 ...
- 水溶彩铅的特点&技法运用
工欲善其事必先利其器!亲爱的同学们都准备好画笔了吗?今天,助助为同学们介绍一下水溶性彩色铅笔的特点,技法运用的基本教程,请仔细看哟! [水溶性彩色铅笔的特点] 能够同时画出像铅笔一样的线条和水彩一样的 ...
- Struts2-tomcat报错:There is no Action mapped for namespace / and action
HTTP Status 404 - There is no Action mapped for namespace / and action name first. type Status repor ...
- 快速解决mysql Lost connection to MySQL server at 'reading initial communication packet及can't connect to mysql server on 'localhost'
今天在使用Navicat连一个远程mysql时,总是提示连接不成功,提示Lost connection to MySQL server at 'reading initial communicatio ...
- JS高级程序设计2nd部分知识要点5
JS Regexp 字面量模式 用\反斜杠转义 构造函数中的字符串 也用\转义正则也用\ RegExp实例属性 global -布尔值 /g ignoreCase -布尔值 /i lastIndex ...
- centos7.2 yum安装lamp环境
一.准备工作 1. 下载并安装centos7.2,配置好网络环境,确保centos能上网,可以获取到yum源. centos7.2的下载地址:http://pan.baidu.com/s/1eRT ...
- URAL 1430 Crime and Punishment
Crime and Punishment Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- docker基础命令详解
Commands: attach Attach to a running container build Build an image from a Dockerfile commit ...
- 关于 SSIS 并行foreach loop的一个设计思路
SSIS 包在控制流方面的性能优化,主要是提高并行度. 可以设置并发线程数MaxConcurrentExecuteables. SSIS中的foreach loop container 不是并行执行任 ...