HDU1848 Fibonacci again and again 博弈 SG函数
题意:三堆石子,每次能拿走斐波那契数个石子,先取完石子胜,问先手胜还是后手胜 石子个数<=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函数的更多相关文章
- S-Nim HDU 1536 博弈 sg函数
S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...
- HDU 1848 Fibonacci again and again (斐波那契博弈SG函数)
Fibonacci again and again Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & ...
- 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)运算 ...
- hdu 3032(博弈sg函数)
题意:与原来基本的尼姆博弈不同的是,可以将一堆石子分成两堆石子也算一步操作,其它的都是一样的. 分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求sg函数,现在我们只能通过找规律的办 ...
- HDU-4678 Mine 博弈SG函数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4678 题意就不说了,太长了... 这个应该算简单博弈吧.先求联通分量,把空白区域边上的数字个数全部求出 ...
- hdu_1848_Fibonacci again and again(博弈sg函数)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 题意:给你3堆石子,每次只能取fibonacci数的石子,问先手是否能赢 题解:SG函数模版题 ...
- (转)博弈 SG函数
此文为以下博客做的摘要: https://blog.csdn.net/strangedbly/article/details/51137432 ---------------------------- ...
- 尼姆博弈+SG函数
博弈这个东西真的很费脑诶.. 尼姆博奕(Nim Game):游戏者轮流从一堆棋子(或者任何道具)中取走一个或者多个,最后不能再取的就是输家.当指定相应数量时,一堆这样的棋子称作一个尼姆堆 当n堆棋子的 ...
- 【转】博弈—SG函数
转自:http://chensmiles.blog.163.com/blog/static/12146399120104644141326/ http://blog.csdn.net/xiaofeng ...
随机推荐
- java中length与length()
length是对数组而言的,指的是数组的长度. length()是对字符串而言的,指的是字符串所包含的字符个数. public class LengthDemo { public static voi ...
- Linux 下Tomcat单机多应用
修改/etc/profile 下,增加如下两个tomcat的配置.apache-tomcat-8.0.50为第一个tomcat, apache-tomcat-8.0.50_2为第二个tomcat ex ...
- 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
问题 rds_content = "{}, 执行了变更,sql语句:{}".format(ExecuteTime, sqls) 'ascii' codec can't encode ...
- ubantu 重启mysql
如何启动/停止/重启MySQL一. 启动方式 1.使用 service 启动:service mysql start 2.使用 mysqld 脚本启动:/etc/inint.d/mysql start ...
- ROS学习材料/链接
ROS的3D模型建立:http://blog.csdn.net/sujun3304/article/details/18962719 ubuntu14 ROS安装:http://blog.csdn.n ...
- Selenium2+python自动化43-判断title(title_is)
From: https://www.cnblogs.com/yoyoketang/p/6539117.html 前言 获取页面title的方法可以直接用driver.title获取到,然后也可以把获取 ...
- ALGO-10_蓝桥杯_算法训练_集合运算(排序)
问题描述 给出两个整数集合A.B,求出他们的交集.并集以及B在A中的余集. 输入格式 第一行为一个整数n,表示集合A中的元素个数. 第二行有n个互不相同的用空格隔开的整数,表示集合A中的元素. 第三行 ...
- 查AIX 版本和系统参数
查AIX版本 atii:[/home/pmts]oslevel -s 7100-01-07-1316 即AIX 7.1版本atii:[/home/pmts]lsdev -C 查CPU个数 (逻辑数目) ...
- 组合(composite)模式
定义 将对象组合成树形结构以表示“部分-整体”的层次结构,使得用户对单个对象和组合对象的使用具有一致性 组合模式(Composite)将小对象组合成树形结构,使用户操作组合对象如同操作一个单个对象.组 ...
- PAT 乙级 1072 开学寄语(20 分)
1072 开学寄语(20 分) 下图是上海某校的新学期开学寄语:天将降大任于斯人也,必先删其微博,卸其 QQ,封其电脑,夺其手机,收其 ipad,断其 wifi,使其百无聊赖,然后,净面.理发.整衣, ...