hdu 2516 取石子游戏 (FIB博弈)
2016-07-30 09:03
465 查看
取石子游戏
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4223 Accepted Submission(s): 2531
Problem Description
1堆石子有n个,两人轮流取.先取者第1次可以取任意多个,但不能全部取完.以后每次取的石子数不能超过上次取子数的2倍。取完者胜.先取者负输出”Second win”.先取者胜输出”First win”.
Input
输入有多组.每组第1行是2<=n<2^31. n=0退出.
Output
先取者负输出”Second win”. 先取者胜输出”First win”.
参看Sample Output.
Sample Input
2
13
10000
0
Sample Output
Second win
Second win
First win
思路:经典的FIB博弈模型题.
ac代码:
/* *********************************************** Author : AnICoo1 Created Time : 2016-07-30-08.39 Saturday File Name : D:\MyCode\2016-7月\2016-7-30.cpp LANGUAGE : C++ Copyright 2016 clh All Rights Reserved ************************************************ */ #include<stdio.h> #include<math.h> #include<string.h> #include<stack> #include<set> #include<map> #include<queue> #include<vector> #include<iostream> #include<algorithm> #define MAXN 1010000 #define LL long long #define ll __int64 #define INF 0xfffffff #define mem(x) memset(x,0,sizeof(x)) #define PI acos(-1) #define eps 1e-8 using namespace std; ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;} ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;} double dpow(double a,ll b){double ans=1.0;while(b){if(b%2)ans=ans*a;a=a*a;b/=2;}return ans;} //head ll fib[110]; int main() { fib[1]=1;fib[2]=2; for(int i=3;i<=50;i++) fib[i]=fib[i-1]+fib[i-2]; int n; while(scanf("%d",&n)!=EOF,n) { int bz=0; for(int i=1;i<=50;i++) if(fib[i]==n) bz=1; if(bz) printf("Second win\n"); else printf("First win\n"); } return 0; }
相关文章推荐
- You must restart adb and Eclipse
- 5-26 单词长度 (15分)
- cookie,session专题2-1:springmvc中jsonp跨域的几种解决方案
- json数据格式 与 for in
- linux用户登录时无法默认进入bash的解决办法
- monolog文档解读
- Spark on Yarn 图
- 456
- 内存分配:堆、栈、全局变量/静态变量、代码区
- PHP 相关知识点
- tjut 4655
- 【博弈论】POJ[2348]Euclid's Game
- [LightOJ 1265] Island of Survival (概率)
- HDU1312 BFS-Numerically Speaking
- Composer常见问题
- 知识点
- jQuery动画效果(show与hide/toggle/slideUp/slideToggle/fadeIn/fadeTo)
- 杭电-1241 Oil Deposits(广搜)
- 原地归并排序
- 12346