hdu1893Fibonacci相关

Now Sempr found another Numbers, he named it "Sibonacci Numbers", the definition is below: 
f(x)=0 (x<0) 
f(x)=1 (0<=x<1) 

f(x)=f(x-1)+f(x-3.14) (x>=1) 

将每项都乘以100,就可以按照正常的斐波那契来做。输入采用字符串,在处理符号时方便。。。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define Mod 1000000007
long long s[100100];
void init()
{
    int i;
    for(i=0;i<100;i++)
        s[i]=1;
    for(i=100;i<100100;i++)
    {
        if(i<314)
            s[i]=s[i-100]%Mod;
        else
            s[i]=(s[i-100]+s[i-314])%Mod;
    }
}
int main()
{
    int cas,n,i,len;
    char ch[20];
    init();
    scanf("%d",&cas);
    while(cas--)
    {
        scanf("%s",ch);
        n=0;
        i=0;
        if(ch[0]=='-')
        {
            printf("0\n");
            continue;
        }
        len=strlen(ch);
        while(ch[i]!='.'&&i<len)
            n=n*10+ch[i++]-'0';
        if(i+1<len)
            n=n*10+ch[i+1]-'0';
        else
            n=n*10;
        if(i+2<len)
            n=n*10+ch[i+2]-'0';
        else
            n=n*10;
        printf("%lld\n",s[n]);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值