zoukankan      html  css  js  c++  java
  • #SG函数#HDU 1848 Fibonacci again and again

    题目


    分析

    可取状态只能是斐波那契数,求出SG函数
    然后判断三个数sg函数异或和不为0先手必胜


    代码

    #include <cstdio>
    #include <cctype>
    #define rr register
    using namespace std;
    const int p[15]={1,2,3,5,8,13,21,34,55,89,144,233,377,610,987};
    const int N=1011; int sg[N],v[N];
    inline signed iut(){
    	rr int ans=0; rr char c=getchar();
    	while (!isdigit(c)) c=getchar();
    	while (isdigit(c)) ans=(ans<<3)+(ans<<1)+(c^48),c=getchar();
    	return ans;
    }
    signed main(){
    	for (rr int i=1;i<N;++i){
    		for (rr int j=0;j<15&&p[j]<=i;++j)
    		    v[sg[i-p[j]]]=1;
    		for (;v[sg[i]];++sg[i]);
    		for (rr int j=0;j<15&&p[j]<=i;++j)
    		    v[sg[i-p[j]]]=0;
    	}
    	while (1){
    		rr int n=iut(),m=iut(),k=iut();
    		if (!n&&!m&&!k) break;
    		if (sg[n]^sg[m]^sg[k]) puts("Fibo");
    		    else puts("Nacci");
    	}
    	return 0;
    }
    
  • 相关阅读:
    (一)Sturts2概述
    day18,常用的模块,os,sys...等
    day17,模块的导入
    day16
    day15
    day14
    day13
    day12
    day11
    day10
  • 原文地址:https://www.cnblogs.com/Spare-No-Effort/p/14619215.html
Copyright © 2011-2022 走看看