# HDU 1848 Fibonacci again and again(SG函数)

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10069    Accepted Submission(s): 4289

Problem Description

F(1)=1;
F(2)=2;
F(n)=F(n-1)+F(n-2)(n>=3);

1、  这是一个二人游戏;
2、  一共有3堆石子，数量分别是m, n, p个；
3、  两人轮流走;
4、  每走一步可以选择任意一堆石子，然后取走f个；
5、  f只能是菲波那契数列中的元素（即每次只能取1，2，3，5，8…等数量）；
6、  最先取光所有石子的人为胜者；

Input

m=n=p=0则表示输入结束。

Output

Sample Input
1 1 1 1 4 1 0 0 0

Sample Output
Fibo Nacci

Author
lcy

Source

Recommend
lcy   |   We have carefully selected several similar problems for you:  1850 1849 2147 2149 2188

Nim游戏的变形，

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1001;
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int SG[MAXN], S[MAXN], Lim, N, f[MAXN] = {0, 1};
int main() {
for(int i = 2; i <= 20; i++) f[i] = f[i - 1] + f[i - 2];
N = 1001;
for(int i = 1; i <= N; i++) {
memset(S, 0, sizeof(S));
for(int j = 1; j <= 20 && f[j] <= i; j++) S[SG[i - f[j]]] = 1;
for(int j = 0; j <= N; j++) if(!S[j]) {SG[i] = j; break;}
}
int a, b, c;
while(scanf("%d %d %d", &a, &b, &c)) {
if(!a && !b && !c) break;
puts(SG[a] ^ SG[b] ^ SG[c] ? "Fibo" : "Nacci");
}
return 0;
}

posted @ 2018-12-10 21:41  自为风月马前卒  阅读(649)  评论(0编辑  收藏  举报