题意:三堆石子,每次能拿走斐波那契数个石子,先取完石子胜,问先手胜还是后手胜  石子个数<=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. java-线程(runoob.com)

    参考链接: https://www.cnblogs.com/wxd0108/p/5479442.html https://www.cnblogs.com/dolphin0520/p/3920373.h ...

  2. HanLP中人名识别分析详解

    HanLP中人名识别分析详解 在看源码之前,先看几遍论文<基于角色标注的中国人名自动识别研究> 关于命名识别的一些问题,可参考下列一些issue: l ·名字识别的问题 #387 l ·机 ...

  3. RedHat7.3安装MySQL5.7

    1.下载Mysql安装包 https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.20-1.el6.x86_64.rpm-bundle.tar 附百度 ...

  4. AI硬件 XPU

    市场对人工智能的热情持续高涨,特别是硬件领域.人工智能将成为下一个大风口,首当其冲的就包括硬件, 在图像语音识别.无人驾驶等人工智能领域的运用层面,图形处理器 (GPU)正迅速扩大市场占比,而谷歌专门 ...

  5. NetBeans IDE 多行标签设置方法

  6. xftp找不到匹配的outgoing encryption 算法 怎么解决

    alert("找不到匹配的outgoing encryption 算法"); 原因,是ssh登录本地终端缓存了相关的安全确认信息: 远端的ssh服务升级后,其对应的加密算法均作了升 ...

  7. VisualSVNServer 无法启动 could not log pid to file

    启动SVN时候报了错误,然后查看日志发现报了如下错误 VisualSVNServer.exe: could not log pid to file C:/Windows/ServiceProfiles ...

  8. PAT 乙级 1047 编程团体赛(20) C++版

    1047. 编程团体赛(20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 编程团体赛的规则为:每个参赛队由若 ...

  9. Maven项目下update maven后Eclipse报错

    Maven项目下update maven后Eclipse报错:java.lang.ClassNotFoundException: ContextLoaderL     严重: Error config ...

  10. Java队列Queue

    上个星期总结了一下synchronized相关的知识,这次将Queue相关的知识总结一下,和朋友们分享. 在Java多线程应用中,队列的使用率很高,多数生产消费模型的首选数据结构就是队列.Java提供 ...