首页 > ACM题库 > HDU-杭电 > HDU 1893 Sibonacci Numbers-字符串处理-[解题报告] C++
2013
12-23

HDU 1893 Sibonacci Numbers-字符串处理-[解题报告] C++

Sibonacci Numbers

问题描述 :

As is known to all, the definition of Fibonacci Numbers is:
f(1)=1
f(2)=1
f(n)=f(n-1)+f(n-2) (n>=3)

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)

Your work is to tell me the result of f(x), is the answer is too large, divide it by 1000000007 and give me the remainder.
Be careful the number x can be an integer or not.

输入:

In the first line there is an Integer T(0<T<=10000) which means the number of test cases in the input file.
Then followed T different lines, each contains a number x(-1000<x<1000).

输出:

For each case of the input file, just output the result, one for each line.

样例输入:

3
-1
0.667
3.15

样例输出:

0
1
2

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;
}

解题报告转自:http://blog.csdn.net/karen_mo/article/details/7779639


  1. 站长,你好!
    你创办的的网站非常好,为我们学习算法练习编程提供了一个很好的平台,我想给你提个小建议,就是要能把每道题目的难度标出来就好了,这样我们学习起来会有一个循序渐进的过程!