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

利用计算grundy数组,把一类博弈转化为nim博弈,最后x不为0为先手必胜态

#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
using namespace std ; //N堆硬币,每堆Xi
//每次从一堆中取a1 a2...ak,先取完胜 const int MAX_X=;
const int MAX_K=;
const int MAX_N=; int N, K, X[MAX_N], A[MAX_K]; int grundy[MAX_X]; void solveSG() {
grundy[] = ;
//int max_x = *max_element(X, X + N);
for(int j = ; j <= ; j++) {
set <int> s;
for(int i = ; i < ; i++){ //A[i] <= j
if(A[i] <= j) s.insert(grundy[j-A[i]]);
}
int g = ;
while(s.count(g)) g++;
grundy[j] = g;
}
/*
int x = 0;
for(int i = 0; i < N; i++) x ^= grundy[X[i]];
if(x) puts("Fibo");//先手胜
else puts("Nacci");//后手胜
*/
} int main() {
A[] = A[] = ;
for(int i = ; i < ; i++)
A[i] = A[i-] + A[i-];
solveSG();
while(~scanf("%d%d%d", &X[], &X[], &X[])) {
if(!X[] && !X[] && !X[]) break;
int x = ;
for(int i = ; i < ; i++) x ^= grundy[X[i]];
if(x) puts("Fibo");//先手胜
else puts("Nacci");//后手胜
}
return ;
}

HDU 1848的更多相关文章

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

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

  2. SG函数入门&&HDU 1848

    SG函数 sg[i]为0表示i节点先手必败. 首先定义mex(minimal excludant)运算,这是施加于一个集合的运算,表示最小的不属于这个集合的非负整数.例如mex{0,1,2,4}=3. ...

  3. hdu 1848 简单SG函数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 Problem Description 任何一个大学生对菲波那契数列(Fibonacci num ...

  4. 【hdu 1848】Fibonacci again and again

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

  5. hdu 1848 sg——dfs&&打表双实现

    Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  6. HDU 1848 SG函数博弈

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

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

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

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

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

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

随机推荐

  1. Objective-C:Foundation框架-常用类-NSObject

    NSObject是所有类的基类,其常见用法有: #import <Foundation/Foundation.h> @interface Person : NSObject - (void ...

  2. uva 10723

      10723 - Cyborg Genes Time limit: 3.000 seconds Problem F Cyborg Genes Time Limit 1 Second Septembe ...

  3. git的一个merge流程

    git merge testSupport 合并testSupport分支代码到当前分支. 若无冲突发生,git commit -m "RM ID:5094",在git push即 ...

  4. JDE处理选项

    处理选项为JDE的一种数据结构,命名方式如下: The name of a data structure can be a maximum of characters-only if you begi ...

  5. 25个有用和方便的 WordPress 速查手册

    如果你是一个 WordPress 编码器或开发人员,下载一些方便的 WordPress 备忘单寻找你的工作然后你在正确的地方.我们已经列出了25个有用的和方便的 WordPress 速查手册.Word ...

  6. mysql 游标取值为空的问题

    DELIMITER $$ DROP PROCEDURE IF EXISTS updatePic $$ CREATE PROCEDURE updatePic() BEGIN DECLARE cover_ ...

  7. 一步一步配置NLB

    废话不说,配置NLB需要准备以下环境: 1. 至少两个服务器,我的是windows server 2008 R2; 我的两个服务器名分别为NLB3和NLB2,其中NLB3是主,为什么呢?后面会谈到,在 ...

  8. 火狐和IE的window.event对象详解(转载)

    FF的FIREBUG,不仅能测试JS还能检查CSS错误,是一般常用的. 但它主要检查FF方面的错误,对IE就无能为力了. 要测试IE,就用ieTester,它可以测试IE几乎所有版本(1.0恐怕也用不 ...

  9. Android google map 两点之间的距离

    在Android google map中,有时候会碰到计算两地的距离,下面的辅助类就可以帮助你计算距离: public class DistanceHelper { /** Names for the ...

  10. Vi不显示insert

    edit file :/etc/vim/vimrc.tiny set compatible -> set nocompatible or install vim