题解:尼姆博弈,对于1至1000计算SG函数,每次取最小的前继值,SG值异或为0则为P-position。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 |
#include <cstdio> #include <cstring> using
namespace std; int fbi[30]; int SG[1001]; int m,n,p; int main(){ fbi[0]=0,fbi[1]=1,fbi[2]=2; for ( int
i=3;fbi[i-1]<=1000;i++)fbi[i]=fbi[i-1]+fbi[i-2]; memset (SG,0, sizeof
SG); int
hash[40]; for ( int
i=1;i<=1000;i++){ memset (hash,0, sizeof
hash); for ( int
j=1;fbi[j]<=i;j++)hash[SG[i-fbi[j]]]=1; for ( int
j=0;;j++) if (hash[j]==0){SG[i]=j; break ;} } while ( scanf ( "%d%d%d" ,&m,&n,&p),m||n||p){ if ((SG[m]^SG[n]^SG[p])!=0) printf ( "Fibo\n" ); else
printf ( "Nacci\n" ); } return
0; } |
HDU 1848 Fibonacci again and again,布布扣,bubuko.com
HDU 1848 Fibonacci again and again
原文:http://www.cnblogs.com/forever97/p/3676353.html