[恢]hdu 1848
2011-12-23 09:32:51
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1848
题意:中文。
mark:求SG值后,1秒钟变NIM。
代码:
# include <stdio.h>
# include <stdlib.h>
int fib[] = {1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597} ;
int sg[1010] = {0, 1} ;
int cmp(const void *a, const void *b)
{
return *(int*)a - *(int*)b ;
}
int met(int n)
{
int i, cnt = 0 ;
int num[20] ;
for (i = 0 ; fib[i] <= n ; i++)
num[cnt++] = sg[n-fib[i]] ;
qsort(num, cnt, 4, cmp) ;
if (num[0] != 0) return 0 ;
for (i = 1 ; i < cnt ; i++)
if(num[i-1]+1 < num[i]) return num[i-1]+1 ;
return num[cnt-1] + 1 ;
}
int main()
{
int i, m,n,p ;
for (i = 2 ; i <= 1000 ; i++)
sg[i] = met(i) ;
while (~scanf ("%d%d%d", &m, &n, &p) && (m||n||p))
puts (sg[m]^sg[n]^sg[p] ? "Fibo" : "Nacci") ;
return 0 ;
}