链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1848

题意:

任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的:

F(1)=1;

F(2)=2;

F(n)=F(n-1)+F(n-2)(n>=3);

所以,1,2,3,5,8,13……就是菲波那契数列。

在HDOJ上有不少相关的题目,比如1005 Fibonacci again就是曾经的浙江省赛题。

今天,又一个关于Fibonacci的题目出现了,它是一个小游戏,定义如下:

1、 这是一个二人游戏;

2、 一共有3堆石子,数量分别是m, n, p个;

3、 两人轮流走;

4、 每走一步可以选择任意一堆石子,然后取走f个;

5、 f只能是菲波那契数列中的元素(即每次只能取1,2,3,5,8…等数量);

6、 最先取光所有石子的人为胜者;

假设双方都使用最优策略,请判断先手的人会赢还是后手的人会赢。

思路:

求出SG函数,判断

代码:

// #include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string.h>
#include<set>
#include<queue>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int MOD = 1e9;
const int MAXN = 1e3+10; int Vis[MAXN], Sg[MAXN];
int F[MAXN];
int n, m, p; int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
F[1] = 1, F[2] = 2;
for (int i = 3;F[i-1] <= 1000;i++)
F[i] = F[i-1]+F[i-2];
Sg[0] = 0;
for (int i = 1;i <= 1000;i++)
{
memset(Vis, 0, sizeof(Vis));
for (int j = 1;F[j] <= i;j++)
Vis[Sg[i-F[j]]] = 1;
for (int j = 0;;j++) if (Vis[j] == 0)
{
Sg[i] = j;
break;
}
}
while(~scanf("%d%d%d", &n, &m, &p) && n)
{
if ((Sg[n]^Sg[m]^Sg[p]) == 0)
puts("Nacci");
else
puts("Fibo");
} return 0;
}

HDU-1848-Fibonacci again and again(SG函数,博弈)的更多相关文章

  1. HDU 1848 Fibonacci again and again(SG函数)

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  2. HDU 1848 Fibonacci again and again SG函数做博弈

    传送门 题意: 有三堆石子,双方轮流从某堆石子中去f个石子,直到不能取,问先手是否必胜,其中f为斐波那契数. 思路: 利用SG函数求解即可. /* * @Author: chenkexing * @D ...

  3. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  4. hdu 1848 Fibonacci again and again(SG函数)

    Fibonacci again and again HDU - 1848 任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的: F(1)=1; F(2)= ...

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

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

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

  7. hdu 1848 Fibonacci again and again (初写SG函数,详解)

    思路: SG函数的应用,可取的值为不连续的固定值,可用GetSG求出SG,然后三堆数异或. SG函数相关注释见代码: 相关详细说明请结合前一篇博客: #include<stdio.h> # ...

  8. HDU 1848 Fibonacci again and again(SG函数入门)题解

    思路:SG打表 参考:SG函数和SG定理[详解] 代码: #include<queue> #include<cstring> #include<set> #incl ...

  9. hdu 1848 Fibonacci again and again 组合游戏 SG函数

    题目链接 题意 三堆石子,分别为\(m,n,p\)个,两人依次取石子,每次只能在一堆当中取,并且取的个数只能是斐波那契数.最后没石子可取的人为负.问先手会赢还是会输? 思路 直接按定义计算\(SG\) ...

  10. HDU 1848 Fibonacci again and again【博弈SG】

    Problem Description 任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的: F(1)=1; F(2)=2; F(n)=F(n-1)+F( ...

随机推荐

  1. 【Python】处理Excel的库Xlwings

    # # 引入库 import xlwings as xw import time # 打开Excel程序,默认设置:程序可见,只打开不新建工作薄 # app = xw.App(visible=True ...

  2. 从nsurlsession、Alamofire到moya

    更好的理解(抽象).更少的构建(配置).更方便的表达(语言) 一.iOS系统的网络编程(DSL概念) ios缺省的网络编程只是给出了网络编程的基本概念: urlsession.request.resp ...

  3. ML学习笔记之Anaconda中命令形式安装XGBoost(pip install)

    0x00 概述 在没有安装XGBoost之前,import xgboot会出错,如下: # ModuleNotFoundError: No module named ‘xgboost’ 0x01 安装 ...

  4. 前端1-----HTML了解,内联标签(图片,超链接锚点,超链接邮箱)

    前端1-----HTML了解,内联标签(图片,超链接锚点,超链接邮箱) 一丶自定制B/S # -*-coding:utf-8-*- # Author:Ds import socket IP_PORT= ...

  5. java并发值多线程同步业务场景以及解决方案

    1.20个人排队同时访问2个购票窗口,同时能购票的只有两个人,当其中一个人买票完成后,18个人中的其中一个在占用窗口进行购买. 20个人相当于20个线程,2相当于资源,当18个人等待的时候,相当于线程 ...

  6. Tensorflow快餐教程(1) - 30行代码搞定手写识别

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/lusing/article/details ...

  7. PostgreSQL 基本数据类型及常用SQL 函数操作

    数据类型 名字 别名 描述 bigint int8 有符号的8字节整数 bigserial serial8 自动增长的8字节整数 bit [ (n) ]   定长位串 bit varying [ (n ...

  8. 打造属于你的提供者(Provider = Strategy + Factory Method) 设计模式 - Provider Pattern(提供者模式)

    打造属于你的提供者(Provider = Strategy + Factory Method)   1.1.1 摘要 在日常系统设计中,我们也许听说过提供者模式,甚至几乎每天都在使用它,在.NET F ...

  9. css animation动画使用

    <!-- animation 属性是一个简写属性,用于设置六个动画属性: animation-name animation-duration animation-timing-function ...

  10. NumPy 之 案例(随机漫步)

    import numpy as np The numpy.random module supplements(补充) the built-in Python random with functions ...