思路:SG打表

参考:SG函数和SG定理【详解】

代码:

#include<queue>
#include<cstring>
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<vector>
#include<cstdio>
#include<iostream>
#include<algorithm>
#define eps 1e-9
typedef long long ll;
const int maxn = 1e3 + ;
const int seed = ;
const ll MOD = 1e9 + ;
const int INF = 0x3f3f3f3f;
using namespace std;
int fib[];
int s[maxn], sg[maxn];
void getSG(){
sg[] = ;
for(int i = ; i <= ; i++){
memset(s, , sizeof(s));
for(int j = ; fib[j] <= i; j++){
s[sg[i - fib[j]]] = ;
}
for(int j = ; j <= i; j++){
if(!s[j]){
sg[i] = j;
break;
}
}
}
}
void FIB(){
fib[] = , fib[] = ;
for(int i = ; i <= ; i++)
fib[i] = fib[i - ] + fib[i - ];
}
int main(){
int n, m, p;
FIB();
getSG();
while(scanf("%d%d%d", &n, &m ,&p) && n + m + p){
if(sg[n] ^ sg[m] ^ sg[p]) printf("Fibo\n");
else printf("Nacci\n");
}
return ;
}

HDU 1848 Fibonacci again and again(SG函数入门)题解的更多相关文章

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

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

  2. HDU 1848 Fibonacci again and again SG函数做博弈

    传送门 题意: 有三堆石子,双方轮流从某堆石子中去f个石子,直到不能取,问先手是否必胜,其中f为斐波那契数. 思路: 利用SG函数求解即可. /* * @Author: chenkexing * @D ...

  3. hdu 1848 Fibonacci again and again(SG函数)

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

  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函数】

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

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

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

  7. hdu 1848 Fibonacci again and again 组合游戏 SG函数

    题目链接 题意 三堆石子,分别为\(m,n,p\)个,两人依次取石子,每次只能在一堆当中取,并且取的个数只能是斐波那契数.最后没石子可取的人为负.问先手会赢还是会输? 思路 直接按定义计算\(SG\) ...

  8. SG函数入门&&HDU 1848

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

  9. HDU 1848 Fibonacci again and again【博弈SG】

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

随机推荐

  1. Photoshop制作倒影的两种方法

    图片加了倒影,画面立刻变得生动起来.而用PS,制作倒影是如此的方便. 素材1 将素材1导入文档,ctrl+J复制图层,编辑-变换-垂直翻转将翻转的图层拖至下方 为翻转的图层添加图层蒙版,选中渐变工具, ...

  2. virtualenvwrapper 的安装和使用(转)

    原文:http://www.cnblogs.com/asmer-stone/p/5470144.html virtualenvwrapper是用来管理virtualenv的扩展包,用着很方便. 1. ...

  3. IO流(3)删除文件或文件夹

    删除功能:public boolean delete() * * 注意: * A:如果你创建文件或者文件夹忘了写盘符路径,那么,默认在项目路径下. * B:Java中的删除不走回收站. * C:要删除 ...

  4. Looper分析。ThreadLocal有关

    Class used to run a message loop for a thread. Threads by default do not have a message loop associa ...

  5. curl 一个无比有用的网站开发工具

    1.Common Line Url Viewer curl是一种命令行工具,作用是发出网络请求,然后得到和提取数据,显示在"标准输出"(stdout)上面. 2.-i参数可以显示h ...

  6. 快捷键(SourceInsight)

    选择一块 : Ctrl+-选择一行 : Shift+F6到下一个函数 : 小键盘 +上一个函数 : 小键盘 -高亮当前单词 : Shift+F8回退.前进 alt + , alt + .最后一个窗口 ...

  7. 万恶之源 - Python初识函数

    什么是函数 我们目前为止,已经可以完成一些软件的基本功能了,那么我们来完成这样一个功能:约x pint("拿出手机") print("打开陌陌") print( ...

  8. sso架构图

  9. yum && 编译 安装mysql 5.7 多实例

    yum安装 [root@localhost ~]# wget http://repo.mysql.com/mysql57-community-release-el7.rpm [root@localho ...

  10. Testbench结构篇

    对于standalone的block的verification: 采用结构化的Testbench:Testcase与Harness,BFM分别分离,来提高系统的可重用性.如图是一个典型结构: 其中所有 ...