[K倍动态减法问题] HDU 2486 & HDU2580 & POJ3922 a simple stone game
来源:互联网 发布:算法之美 pdf 编辑:程序博客网 时间:2024/04/28 19:25
这就是斐波那契博弈的加强版
对于某些特定的
K=1 后手必胜当且仅当n 是2 的次幂 先手的策略是取lowbit(n) K=2 后手必胜当且仅当n 是斐波那契数 先手的策略是取n 的斐波那契拆分中最小的数
这道题 我们仿照斐波那契博弈的构造方法
构造一个数列
将每个自然数都表示成
数列
- 如果该堆石子恰是数列
an 中的一项 后手必胜 - 否则 该堆石子可以表示为
an 中的不连续几项的和 先手必胜 策略是取其中f1 个石子 后手取走的石子不会超过f2 个 继续上述策略 后手永远取不完石子
下面程序中
#include<cstdio>#include<cstdlib>#include<algorithm>#define read(x) scanf("%d",&(x))using namespace std;const int N=5000005;int n,K,a[N],b[N];int main(){ int T,Case=0; freopen("t.in","r",stdin); freopen("t.out","w",stdout); read(T); while (T--){ read(n); read(K); int x=0,y=0; while (a[x]<n){ a[++x]=b[x-1]+1; while (a[y+1]*K<a[x]) y++; if (a[y]*K<a[x]) b[x]=b[y]+a[x]; else b[x]=a[x]; } printf("Case %d: ",++Case); if (n==a[x]) printf("lose\n"); else{ int ans; for (;n;x--) if (n>=a[x]) n-=a[x],ans=a[x]; printf("%d\n",ans); } } return 0;}
0 0
- [K倍动态减法问题] HDU 2486 & HDU2580 & POJ3922 a simple stone game
- hdu2486 hdu2580 poj3922 A simple stone game--K倍动态减法游戏 博弈
- HDU 2486 HDU2580 POJ3922 a simple stone game
- HDU A simple stone game [K倍动态减法游戏]
- HDU 2486 (HDU 2580, POJ 3922) A simple stone game K倍动态减法游戏
- HDU 2486 A simple stone game (K 倍动态减法博弈游戏,还未理解)
- hdu2486 A simple stone game K倍动态减法游戏
- a simple stone game--k倍动态规划减法游戏
- HDOJ 题目2486 A simple stone game(K倍动态减法游戏,模板)
- A simple stone game - HDU 2486 K倍递减博弈
- Poj-3922 A simple stone game(博弈,k倍动态减法)
- uva 1567 - A simple stone game(K倍动态减法游戏)
- 斐波那契博弈-K倍动态减法游戏(Poj-3922 A simple stone game)
- HDU 2580 a simple stone game K倍减法博弈游戏
- hdu2580 a simple stone game
- POJ 3922 A simple stone game(K倍减法游戏)(*)
- POJ 3922 A simple stone game(K倍减法游戏)
- POJ 3922 A simple stone game(K倍减法游戏)
- 动态规划--PAT.A1068.Find More Coins【输出DP序列】
- NSString的几种常用方法
- 笔记 基于OpenCV的目标跟踪软件与系统实现
- 搭建spring4+hibernate4+struts2时用spring管理hibernate事务时发生的问题
- awt--事件适配器--比如WindowAdapter
- [K倍动态减法问题] HDU 2486 & HDU2580 & POJ3922 a simple stone game
- Java中的类的概念
- cocos2d-JS 性能优化
- 使用java中replaceAll方法替换字符串中的反斜杠
- 关于语言选择、输入和产出的关系
- Ubuntu下使用git提交代码至GitHub
- hibernate初体验
- HP大中华区总裁孙振耀退休感言
- 三方支付 -- 支付宝集成