• 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
    ");
    46         else
    47             printf("Nacci
    ");
    48     }
    49     return 0;
    50 }

    石子相关:

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

    ……

  • 相关阅读:
    南阳oj 814 又见拦截导弹
    南阳 zb的生日和邮票分你一般(01背包思路)
    导弹拦截(最长下降子序列)变形
    控件绝对定位函数
    小玩意
    java获取本机所有可用字体
    按键监听类KeyListener及适配器改良方案
    编译php-memcached扩展
    Memcached安装,启动,连接
    Apache配置虚拟主机
  • 原文地址:https://www.cnblogs.com/cmyg/p/11041637.html
Copyright © 2020-2023  润新知