题意:三堆石子,每次能拿走斐波那契数个石子,先取完石子胜,问先手胜还是后手胜  石子个数<=1000 多组数据

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1848

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector> using namespace std; const int MAXN = ;
int n, m, p, lx;
int f[MAXN], sg[MAXN];
bool tf[MAXN]; template <typename tn> void read (tn & a) {
tn x = , f = ;
char c = getchar();
while (c < '' || c > ''){ if (c == '-') f = -; c = getchar(); }
while (c >= '' && c <= ''){ x = x * + c - ''; c = getchar(); }
a = f == ? x : -x;
} int get_f() {
f[] = ;
f[] = ;
f[] = ;
int i;
for (i = ; f[i - ] <= ; ++i) f[i] = f[i - ] + f[i - ];
return i - ;
} void get_() {
sg[] = ;
sg[] = ;
for (int i = ; i <= ; ++i) {
for (int j = ; j <= ; ++j) tf[j] = ;
for (int j = ; j <= lx && f[j] <= i; ++j) {
tf[sg[i - f[j]]] = ;
}
int j = ;
while (!tf[j] && j <= ) ++j;
sg[i] = j;
}
} int main() {
lx = get_f();
get_();
read(n);
read(m);
read(p);
while (n != || m != || p != ) {
if (sg[n] ^ sg[m] ^ sg[p]) printf("Fibo\n"); else printf("Nacci\n");
read(n);
read(m);
read(p);
}
return ;
}

HDU1848 Fibonacci again and again 博弈 SG函数的更多相关文章

  1. S-Nim HDU 1536 博弈 sg函数

    S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...

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

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

  3. 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)运算 ...

  4. hdu 3032(博弈sg函数)

    题意:与原来基本的尼姆博弈不同的是,可以将一堆石子分成两堆石子也算一步操作,其它的都是一样的. 分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求sg函数,现在我们只能通过找规律的办 ...

  5. HDU-4678 Mine 博弈SG函数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4678 题意就不说了,太长了... 这个应该算简单博弈吧.先求联通分量,把空白区域边上的数字个数全部求出 ...

  6. hdu_1848_Fibonacci again and again(博弈sg函数)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 题意:给你3堆石子,每次只能取fibonacci数的石子,问先手是否能赢 题解:SG函数模版题 ...

  7. (转)博弈 SG函数

    此文为以下博客做的摘要: https://blog.csdn.net/strangedbly/article/details/51137432 ---------------------------- ...

  8. 尼姆博弈+SG函数

    博弈这个东西真的很费脑诶.. 尼姆博奕(Nim Game):游戏者轮流从一堆棋子(或者任何道具)中取走一个或者多个,最后不能再取的就是输家.当指定相应数量时,一堆这样的棋子称作一个尼姆堆 当n堆棋子的 ...

  9. 【转】博弈—SG函数

    转自:http://chensmiles.blog.163.com/blog/static/12146399120104644141326/ http://blog.csdn.net/xiaofeng ...

随机推荐

  1. 微信支付app的各种坑

    android: 签名要一致,要导出singed包 要记得重启手机 如果别人的都可以支付,我的不可以,就要退出微信账号,重新登陆微信账号一下(不仅仅是退出微信应用). 上面还不行的话,就要重新换个微信 ...

  2. USB引脚定义

  3. Delphi实现菜单项上出现提示

    type TMenuHintWindow = class(THintWindow) private FTimerShow: TTimer; FTimerHide: TTimer; procedure ...

  4. WINDOWS 命令行 串口 COM 发送数据

    WINDOWS 命令 串口 数据 type con>com1 回车. com1 为想发送的串口. 输入字符并回车即可.

  5. Flutter at Google I/O 2018

    Flutter at Google I/O 2018   如何观看 https://flutterchina.club/ 极速构建漂亮的原生应用 Flutter是谷歌的移动UI框架,可以快速在iOS和 ...

  6. mysql数据字典 如何生成?

    用phpMyAdmin查看表结构,点击 打印预览. &amp;lt;img src="https://pic3.zhimg.com/50/3205ff3bd3da067528f4c1 ...

  7. IntelliJ IDEA Configuring projects

    https://www.jetbrains.com/help/idea/configuring-projects.html Configuring projects A project in Inte ...

  8. RTB业务知识之2-Open-RTB全景

    一.前言 openrtb是一套开源的竞价广告系统,来自IAB的贡献,非常好.有非常多的值得借鉴的地方,最近基于其所提供sdk api接口文档介绍,整理了相关的资料.主要包括其生态图体系.业务流程和主要 ...

  9. Netty Tutorial Part 1: Introduction to Netty [z]

    Netty Tutorial, Part 1: Introduction to Netty Update:  Part 1.5 Has Been Published: Netty Tutorial P ...

  10. Javascript中的词法作用域、动态作用域、函数作用域和块作用域(四)

    一.js中的词法作用域和动态作用域      词法作用域也就是在词法阶段定义的作用域,也就是说词法作用域在代码书写时就已经确定了.       js中其实只有词法作用域,并没有动态作用域,this的执 ...