Problem Description
有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行。请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数。
其中,蜂房的结构如下所示。
Input
输入数据的第一行是一个整数N,表示测试实例的个数,然后是N 行数据,每行包含两个整数a和b(0<a<b<50)。
Output
对于每个测试实例,请输出蜜蜂从蜂房a爬到蜂房b的可能路线数,每个实例的输出占一行。
Sample Input
2 1 2 3 6
Sample Output
1 3
Author
lcy
这就是一个菲波拉契数列,但是要注意数据最后特别大,需要用lld,甚至于unsigned
原题链接http://acm.hdu.edu.cn/showproblem.php?pid=2044
代码如下:
#include<stdio.h>
unsigned long long fn[53];//a[1]表示去第1个位置有多少路
void setfn()
{
int i;
fn[0] = 0;
fn[1] = 0;
fn[2] = 1;
fn[3] = 2;
for(i=4; i<=52; i++)
fn[i] = fn[i-2] + fn[i-1];
}
int main()
{
int n,a,b;
setfn();
scanf("%d",&n);
while(n--)
{
// 读入a和b
scanf("%d%d", &a, &b);
// 输出结果
printf("%lld\n", fn[b - a + 1]);
}
return 0;
}