zoukankan      html  css  js  c++  java
  • 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

    ……

  • 相关阅读:
    linux 基础笔记(一)
    wysiwyg加ckeditor加 代码高亮
    将html转换为Drupal模板文件的一般步骤
    最重要的7个Drupal内核模板文件
    drupal模板命名规则
    mysql存储过程和事件
    阿里云图片压缩上传代码
    BeanUtils No value specified for Date的解决方法
    mysql SQLyog导入导出csv文件
    mysql去除重复查询的SQL语句基本思路
  • 原文地址:https://www.cnblogs.com/cmyg/p/11041637.html
Copyright © 2011-2022 走看看