对于SG函数来说,sg[y]=x的意义为,x与y的输赢状态是相同的

sg[y]=mex(y)的定义与n.p点的定义是相同的

#include<iostream>
#include<cstring>
using namespace std;
int SG[1001],f[20]={1,2};
int flag[20];
void getfibo()
{
    int i;
    for(i=2;i<=15;i++) f[i]=f[i-1]+f[i-2];
}
void getSG(int x)
{
    int i,j;
    memset(SG,0,sizeof(SG));
    for(i=0;i<x;i++)//对i点的SG值进行搜索
    {
        memset(flag,0,sizeof(flag));
        for(j=0;f[j]<=i;j++)//对i点所有后继点的SG值进行标记
        {
            flag[SG[i-f[j]]]=1;
        }//
        for(j=0;;j++)//搜索没有被标记的最小值
        {
            if(flag[j]==0)
            {
                SG[i]=j;
                break;
            }
        }
    }
}
int main()
{
    int m,n,p;
    int t1,t2,t3;
    int ans;
    int i;
    getfibo();
    getSG(1000);
    for(i=0;i<30;i++) cout<<SG[i]<<" ";
    while(cin>>m>>n>>p)
    {
        if(m==0&&n==0&&p==0) break;
        ans=SG[m]^SG[n]^SG[p];
        if(ans==0) cout<<"Nacci"<<endl;
         else cout<<"Fibo"<<endl;
    }
    return 0;
}

HDOJ 1848(SG函数)的更多相关文章

  1. hdu 1848(SG函数)

    Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  2. HDU 1848 SG函数博弈

    Fibonacci again and again Problem Description   任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的:F(1 ...

  3. hdu 1848 简单SG函数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 Problem Description 任何一个大学生对菲波那契数列(Fibonacci num ...

  4. HDU 1848 Fibonacci again and again (斐波那契博弈SG函数)

    Fibonacci again and again Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & ...

  5. HDU 1848 Fibonacci again and again(SG函数)

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  6. SG函数入门&&HDU 1848

    SG函数 sg[i]为0表示i节点先手必败. 首先定义mex(minimal excludant)运算,这是施加于一个集合的运算,表示最小的不属于这个集合的非负整数.例如mex{0,1,2,4}=3. ...

  7. HDU 1848 Fibonacci again and again【SG函数】

    对于Nim博弈,任何奇异局势(a,b,c)都有a^b^c=0. 延伸: 任何奇异局势(a1, a2,… an)都满足 a1^a2^…^an=0 首先定义mex(minimal excludant)运算 ...

  8. hdu 1848 Fibonacci again and again (初写SG函数,详解)

    思路: SG函数的应用,可取的值为不连续的固定值,可用GetSG求出SG,然后三堆数异或. SG函数相关注释见代码: 相关详细说明请结合前一篇博客: #include<stdio.h> # ...

  9. hdoj 1729 Stone Games(SG函数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1729 看了题目感觉像Nim,但是有范围限制,有点不知道SG函数该怎么写 看了题解,最后才明白该怎么去理 ...

随机推荐

  1. 剑指offer 面试题0:高质的代码:即考虑边界条件、特殊输入和错误处理

    Q:把一个字符串转换为整数. A1:一个普通但漏洞百出的解法. int StrToInt(char* str) { int number = 0; while (*str != 0) { number ...

  2. 【MySql】[ERROR] Can't read from messagefile '/usr/share/mysql/english/errmsg.sys'

    [root@zhang bin]# ./mysql_install_db --datadir=/usr/local/mysql/mydata/data/ 2018-08-18 03:09:14 [WA ...

  3. 【Oracle】查看oracle表空间大小及增加表空间的几种方法

    在oracle中表空间是必不可少的.但是怎么查看表空间呢 简单的查看方式是: SQL> select tablespace_name from dba_tablespaces; 想要查看表空间对 ...

  4. kubernets之服务发现

    一  服务与pod的发现 1.1  服务发现pod是很显而易见的事情,通过简称pod的标签是否和服务的标签一致即可,但是pod是如何发现服务的呢?这个问题其实感觉比较多余,但是接下来你就可能不这么想了 ...

  5. Linux—curl命令讲解

    命令:curl 在Linux中curl是一个利用URL规则在命令行下工作的文件传输工具,可以说是一款很强大的http命令行工具.它支持文件的上传和下载,是综合传输工具,但按传统,习惯称url为下载工具 ...

  6. Ubuntu 能ping通DNS 地址 无法解析域名

    ping通qq百度都行,唯独谷歌不行, 主机能够ping通google的dns服务器地址 8.8.8.8,却无法解析域名   $ ping www.google.co.uk ping: unknown ...

  7. Sapphire: Copying GC Without Stopping the World

    https://people.cs.umass.edu/~moss/papers/jgrande-2001-sapphire.pdf Many concurrent garbage collectio ...

  8. WebRTC 泄漏真实 IP 地址

    WebRTC(网页即时通信,Web Real-Time Communication) 它允许浏览器内进行实时语音或视频对话,而无需添加额外的浏览器扩展.包括 Chrome.Firefox.Opera. ...

  9. (转载)微软数据挖掘算法:Microsoft Naive Bayes 算法(3)

    介绍: Microsoft Naive Bayes 算法是一种基于贝叶斯定理的分类算法,可用于探索性和预测性建模. Naïve Bayes 名称中的 Naïve 一词派生自这样一个事实:该算法使用贝叶 ...

  10. 并发编程:Actors 模型和 CSP 模型

    https://mp.weixin.qq.com/s/emB99CtEVXS4p6tRjJ2xww 并发编程:Actors 模型和 CSP 模型 ImportNew 2017-04-27