hdu_1848_Fibonacci again and again(博弈sg函数)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1848
题意:给你3堆石子,每次只能取fibonacci数的石子,问先手是否能赢
题解:SG函数模版题
#include<cstdio>
#define F(i,a,b) for(int i=a;i<=b;i++)
/*
计算从0-N范围内的SG值。
s(存储可以走的步数,s[0]表示可以有多少种走法)
s[]需要从小到大排序
1.可选步数为1~m的连续整数,直接取模即可,SG(x)=x%(m+1);
2.可选步数为任意步,SG(x) = x;
3.可选步数为一系列不连续的数,用GetSG()计算
*/
const int N=;
int sg[N];bool hash[N];
void get_sg(int *s,int N){
F(i,,N)sg[i]=;
F(i,,N){
F(j,,N)hash[j]=;
for(int j=;s[j]<=i&&j<=s[];j++)hash[sg[i-s[j]]]=;
F(j,,N)if(!hash[j]){sg[i]=j;break;}
}
}
int f[],n,m,p;
int main(){
f[]=,f[]=,f[]=;
F(i,,)f[i]=f[i-]+f[i-];
get_sg(f,);
while(~scanf("%d%d%d",&m,&n,&p),m+n+p){
if(sg[m]^sg[n]^sg[p])puts("Fibo");
else puts("Nacci");
}
return ;
}
hdu_1848_Fibonacci again and again(博弈sg函数)的更多相关文章
- S-Nim HDU 1536 博弈 sg函数
S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...
- hdu 3032(博弈sg函数)
题意:与原来基本的尼姆博弈不同的是,可以将一堆石子分成两堆石子也算一步操作,其它的都是一样的. 分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求sg函数,现在我们只能通过找规律的办 ...
- HDU-4678 Mine 博弈SG函数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4678 题意就不说了,太长了... 这个应该算简单博弈吧.先求联通分量,把空白区域边上的数字个数全部求出 ...
- (转)博弈 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 ...
- HDU 1848 Fibonacci again and again (斐波那契博弈SG函数)
Fibonacci again and again Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & ...
- Light OJ 1199 - Partitioning Game (博弈sg函数)
D - Partitioning Game Time Limit:4000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- LightOJ 1315 - Game of Hyper Knights(博弈sg函数)
G - Game of Hyper Knights Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & ...
随机推荐
- NIC Bonding: 2 nic port as 1 interface
The following is concluded from here. Consider we have 2 interfaces: eth0 & eth1 bond the two in ...
- android从assets读取文件的方法
因为开发需要,经常要从工程的assets文件夹里面读取文件,现在贴一个方法以作记录: private void getFromAssets(String fileName, ArrayList< ...
- B/S、C/S区别
[B/S.C/S C/S (Client/Server客户端服务器) B/S (Brower/Server浏览器服务器) 区别 1.硬件环境不同: C/S 一般建立在专用的网络上, 小范围里的网络环 ...
- 雄冠条码PV系统-2016-05-17-收获
Q1:微信浏览器 input获取焦点时,页面宽度变大 解决方法: HTML <header> 中添加<meta name="viewport" content=& ...
- maven创建spring项目之后,启动报错java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoade
错误: org.apache.catalina.core.StandardContext listenerStart严重: Error configuring application listener ...
- zoj 1718 poj 2031 Building a Space Station
最小生成树,用了Kruskal算法.POJ上C++能过,G++不能过... 算出每两个圆心之间的距离,如果距离小于两半径之和,那么这两个圆心之间的距离直接等于0,否则等于距离-R[i]-R[j]. # ...
- hdu1002
//c//https://github.com/ssdutyuyang199401/hduacm/blob/master/1002.c#include<stdio.h>#include&l ...
- 老司机的奇怪noip模拟T1-guanyu
1. 关羽(guanyu.cpp/c/pas )[问题描述]xpp 每天研究天文学研究哲学,对于人生又有一些我们完全无法理解的思考.在某天无聊学术之后, xpp 打开了 http://web.sang ...
- @InitBinde的作用
@InitBinder用于在@Controller中标注于方法,表示为当前控制器注册一个属性编辑器或者其他,只对当前的Controller有效
- 区块链Readme.md
#Welcome to Azure Blockchain Projects This Repo host Azure related blockchain and distributed ledger ...