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 ...
随机推荐
- JDBC 编程步骤
java访问数据库的步骤如下: 加载数据库驱动 通常使用Class.forName(driverClass)来加载驱动 // 加载MySQL驱动 Class.forName("com.mys ...
- 运用MQTT-JMeter插件测试MQTT服务器性能
今天我们介绍XMeter团队带来的新版MQTT-JMeter插件,您可以更为方便地添加MQTT连接.发布.订阅取样器,构造组合的应用场景,例如背景连接.多发少收.少发多收,计算消息转发时延等.利用该插 ...
- Zookeeper命令行world
world:anyone:cdrwa getAcl /imooc/abc 获得节点abc的权限 设置权限为crwa. setAcl /nick/abc world:anyone:crwa 测试删除权 ...
- jpa随笔
1对多的关系 //多的一方@Entity @Table(name="car_distribute") public class DistributeCar extends Cust ...
- 使用php生成数字、字母组合验证码
项目中经常会遇到一些登陆验证,支付验证等等一系列安全验证的策略.实现方法多种多样,下面就来讲解下如何用php生成简单的文字+数字组合的验证码: 所用语言php,gd库 原理解释: a>实质上是在 ...
- 总线读写---verilog代码
总线读写---verilog代码 `timescale 1ns / 1ps ////////////////////////////////////////////////////////////// ...
- jQuery模态框实现 后台添加删除修改Ip端口
主要用到,$('#i1').each(),标签里绑定函数可传参数this <!DOCTYPE html> <html lang="en"> <head ...
- 代码编辑器之EditPlus
引用及下载地址:http://www.iplaysoft.com/editplus.html EditPlus是一套功能非常强大的文字编辑器,拥有无限制的Undo/Redo(撤销).英文拼字检查.自动 ...
- jquery 中prop和 attr
prop就是给html中元素固有的属性赋值 而attr是给元素定义新的属性值.
- Building the Unstructured Data Warehouse: Architecture, Analysis, and Design
Building the Unstructured Data Warehouse: Architecture, Analysis, and Design earn essential techniqu ...