hust 1003 - Sibonacci Numbers

本文介绍了Sibonacci数列的概念及其与经典Fibonacci数列的区别,详细解释了Sibonacci数列的定义和计算方法,并提供了一段C语言实现的代码样例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原题链接:

http://acm.hust.edu.cn/problem/show/1003


1003 - Sibonacci Numbers

Time Limit: 1s Memory Limit: 64MB

Submissions: 2029 Solved: 348
DESCRIPTION
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.
INPUT
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).
OUTPUT
For each case of the input file, just output the result, one for each line.
SAMPLE INPUT
3
-1
0.667
3.15
SAMPLE OUTPUT
0
1
2
HINT
SOURCE
Sempr|CrazyBird|hust07p43
代码:
#include "stdio.h"
#include "string.h"
#include "math.h"

int f[2000010],mod=1000000007;
int xx;
double x;

long long getf(int a)
{
	if(a<0)
		return 0;
	if(a<1000)
	{
		return 1;
	}
	if(f[a]!=-1)
		return f[a];
	else
	{
		return (getf(a-1000)+getf(a-3140))%mod;
	}
}

void solve()
{
	for(int i=1;i<=1000000;i++)
	{
		f[i]=getf(i);
	}
}

int main()
{
	int T;
	scanf("%d",&T);
	memset(f,-1,sizeof(f));
	solve();
	while(T--)
	{
		scanf("%lf",&x);
		x=floor(x*1000);
		xx=x;
		printf("%d\n",getf(xx));
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值