SG函数

 

study from:

 

https://blog.csdn.net/luomingjun12315/article/details/45555495

SG[0]=0

 

https://zhuanlan.zhihu.com/p/20611132

https://www.jianshu.com/p/e215fe4797c1

 

Fibonacci again and again

http://acm.hdu.edu.cn/showproblem.php?pid=1848

 

下面的vis数组大小可根据实际的打表数值进行减小

 1 #include <cstdio>
 2 #include <cstdlib>
 3 #include <cstring>
 4 #include <string>
 5 #include <cmath>
 6 #include <algorithm>
 7 #include <iostream>
 8 using namespace std;
 9 #define ll long long
10 
11 const int maxn=1e3+10;
12 const int maxv=1e3;
13 
14 int a[maxn],mex[maxn];
15 bool vis[maxn];
16 
17 int main()
18 {
19     int n,m,p,i,j;
20     a[1]=1;
21     a[2]=1;
22     for (i=3;a[i-1]<=maxv;i++)
23         a[i]=a[i-1]+a[i-2];
24     for (i=1;i<=maxv;i++)
25     {
26         memset(vis,0,sizeof(vis));
27         for (j=1;a[j]<=i;j++)
28             vis[mex[i-a[j]]]=1;
29         for (j=0;j<=maxv;j++)
30             if (!vis[j])
31                 break;
32         mex[i]=j;
33     }
34 //    for (i=0;i<=100;i++)
35 //        printf("%d ",mex[i]);
36     /*
37 0 1 2 3 0 1 2 3 4 5 0 1 2 3 0 1 2 3 4 5 0 1 2 3 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 0 1 2 3 4 5 0 1 2 3 0 1 2 3 4 5 0 1 2 3 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 0 1 2 3 4 5 0 1 2 3 0 1 2 3 4 5 0 1 2 3 0 1 2 3 4
38 0 1 2 3 0 1 2 3 4 5 一个循环节
39     */
40     while (~scanf("%d%d%d",&n,&m,&p))
41     {
42         if (n==0)
43             break;
44         if (mex[n]^mex[m]^mex[p])
45             printf("Fibo\n");
46         else
47             printf("Nacci\n");
48     }
49     return 0;
50 }

 

石子相关:

https://blog.csdn.net/qq_33765907/article/details/51174524

……

 

posted @ 2019-06-17 19:18  congmingyige  阅读(148)  评论(0编辑  收藏  举报