2 13 10000 0
Second win Second win First win
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20……
p p n p n n p n n n n p n n n n n n n……
以上PN图可以很容易画出来,必败状态为2,3,5,8,13.。。。其实我没画21时的状态,因为看到必败状态序列是菲波那切数列,所以就直接猜想必败状态符合斐波那契,提交后竟然AC了。。。。
#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <climits> using namespace std; int a,b; int main(){ //freopen("in.txt","r",stdin); //(author : CSDN iaccepted) int n,ts; bool mark; while(scanf("%d",&n) && n){ a = 2,b = 3; mark = false; while(a<=n){ if(a==n || b==n){ mark = true; break; } ts = (a + b); a = b; b = ts; } if(mark){ printf("Second win\n"); }else{ printf("First win\n"); } } return 0; }
HDU 2516 取石子游戏(巴什博弈),布布扣,bubuko.com
原文地址:http://blog.csdn.net/iaccepted/article/details/25301057