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]取石子游戏 - 洛谷 题目背景 无 题目描述 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以 ...
随机推荐
- Flash网站Loading制作
Flash网站Loading制作~~~ stop(); stage.scaleMode=StageScaleMode.NO_SCALE; //指定舞台属性为不跟随播放器大小而改变 stage.show ...
- Effective Java 03 Enforce the singleton property with a private constructor or an enum type
Principle When implement the singleton pattern please decorate the INSTANCE field with "static ...
- MongoDB学习笔记——聚合操作之聚合管道(Aggregation Pipeline)
MongoDB聚合管道 使用聚合管道可以对集合中的文档进行变换和组合. 管道是由一个个功能节点组成的,这些节点用管道操作符来进行表示.聚合管道以一个集合中的所有文档作为开始,然后这些文档从一个操作节点 ...
- js中location.href的用法
Javascript中的location.href有很多种用法,主要如下: self.location.href="/url" 当前页面打开URL页面 ocation.href=& ...
- cocos2d-x之Box2d初试
物理引擎:用来模拟一套物理事件的物理代码. #ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__ #include "c ...
- APP原型设计工具,哪家强?转自知乎
著作权归作者所有. 商业转载请联系作者获得授权,非商业转载请注明出处. 作者:李志超 链接:http://www.zhihu.com/question/20403141/answer/25329730 ...
- Climbing Stairs
Climbing Stairs https://leetcode.com/problems/climbing-stairs/ You are climbing a stair case. It tak ...
- UVALive 6073 Math Magic
6073 Math MagicYesterday, my teacher taught us about m ...
- Ubuntu 14.04 单机安装 CEPH
0.如果先前安装过ceph,则先卸载 sudo stop ceph-all //停止所有CEPH进程 ceph-deploy uninstall [{ceph-node}] //卸载所有ceph程序 ...
- Google三驾马车
Google旧三驾马车: GFS,mapreduce,Bigtable http://blog.sina.com.cn/s/blog_4ed630e801000bi3.html Google新三驾马车 ...