斐波那契博弈 hdu2516 取石子游戏
2015-12-10 18:52
309 查看
传送门:点击打开链接
题意:1堆石子n个,第一个人可以取任意个数但不能全部取完,以后每次拿的个数不能超过上一次对手拿的个数的2倍,轮流拿石子,问先手是否必赢
思路:斐波那契博弈,后手赢的情况的数字会呈现斐波那契数列。
题意:1堆石子n个,第一个人可以取任意个数但不能全部取完,以后每次拿的个数不能超过上一次对手拿的个数的2倍,轮流拿石子,问先手是否必赢
思路:斐波那契博弈,后手赢的情况的数字会呈现斐波那契数列。
#include<map> #include<set> #include<cmath> #include<ctime> #include<stack> #include<queue> #include<cstdio> #include<cctype> #include<string> #include<vector> #include<cstring> #include<iostream> #include<algorithm> #include<functional> #define fuck(x) cout<<"["<<x<<"]" #define FIN freopen("input.txt","r",stdin) #define FOUT freopen("output.txt","w+",stdout) using namespace std; typedef long long LL; const int MX = 50; LL F[MX]; void presolve() { F[1] = 1; F[2] = 2; for(int i = 3; i < 50; i++) { F[i] = F[i - 1] + F[i - 2]; } } bool solve(int n) { for(int i = 1; i < MX; i++) { if(F[i] == n) return false; } return true; } int main() { presolve(); int n; //FIN; while(~scanf("%d", &n), n) { printf("%s\n", solve(n) ? "First win" : "Second win"); } return 0; }
相关文章推荐
- iOS传感器开发——为APP添加手机密码、指纹进行安全验证
- java版本对照表
- QT如何显示中文,解决乱码问题
- 回文子串判别
- 生成一条短信
- iOS9中UIAlertView和UIActionSheet的用法
- warning!no such command:/bootmgr(ud) 老毛桃装机重启失败
- android:launchMode的参数含义
- 在vs2010怎么生成通用exe
- Java一流的施工顺序
- 堆排序
- could not find developer disk image IOS9.2
- Haproxy 与 Cookie
- 最长公共前缀_LinkCode
- 威佐夫博弈变形 poj2348 Euclid's Game
- 盒子模型
- Linux 信号量同步实验
- 伪类选择 器
- 深入理解Tagged Pointer
- 响铃:救市之作三星S6 edge+能否完成使命?