HUST 1003 Sibonacci Numbers(杂题)

来源:互联网 发布:淘宝组装机店铺大牌 编辑:程序博客网 时间:2024/06/05 08:06

题目链接:http://acm.hust.edu.cn/problem.php?id=1003

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)

求f(n)

结果对1000000007取余数

这个转换成整数,然后注意精度,貌似不需要用long long

#include <stdio.h>#include <string.h>#include <algorithm>#include <iostream>#define eps 1e-8using namespace std;const int maxn = 100010;const int mod = 1000000007;int rec[maxn];int init(){    int i,j,k;    for(i=0;i<314;i++)    rec[i]=1;    for(i=314;i<maxn;i++)    rec[i]=(rec[i-100]+rec[i-314])%mod;    return 0;}int main(){    int i,j,k,ans,t;    double w;    init();    scanf("%d",&t);    while(t--){        scanf("%lf",&w);        if(w<0){            printf("0\n");            continue;        }        ans=int((w+eps)*100);        printf("%d\n",rec[ans]);    }    return 0;}


0 0
原创粉丝点击