[COCI2010]HRPA

Description
N个石子,A和B轮流取,A先。每个人每次最少取一个,最多不超过上一个人的个数的2倍。
取到最后一个石子的人胜出,如果A要有必胜策略,第一次他至少要取多少个。

Input
第一行给出数字N,N<=10^15.第二行N个数字

Output
如题

Sample Input
4

Sample Output
1


Fibonacci Nim,详解请见浅谈算法——博弈论中的例7

/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline int read(){
	int x=0,f=1;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')    f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<1)+(x<<3)+ch-'0';
	return x*f;
}
inline void print(int x){
	if (x>=10)     print(x/10);
	putchar(x%10+'0');
}
const int N=80;
ll Fib[N],n;
int main(){
	scanf("%lld",&n);
	Fib[1]=Fib[2]=1;
	for (int i=3;i<N;i++)	Fib[i]=Fib[i-1]+Fib[i-2];
	int m=N-1;
	while (true){
		if (n==Fib[m]){printf("%lld\n",Fib[m]);break;}
		if (n>Fib[m])	n-=Fib[m];
		m--;
	}
	return 0;
}
posted @ 2018-02-08 23:08  Wolfycz  阅读(506)  评论(0编辑  收藏  举报