题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2044
该题目可以利用斐波那契额数组很容易就能做出来,但是要注意的是该数组的成员可能会超出int型可表示的范围,所以这里用了_int64类型。该题目和 HDOJ 2041 超级电梯类似。
#include<stdio.h> #define MAX 50 _int64 fib[MAX]; int main() { int n, a, b, i, len; fib[0] = 1; fib[1] = 1; for(i = 2; i< MAX; i++) fib[i] = fib[i-1] + fib[i-2]; while(scanf("%d",&n) != EOF) { for(i = 0; i < n; i++) { scanf("%d %d",&a,&b); if(a == 1) printf("%I64u\n",fib[b-1]); else { len = a - 1; b = b - len; printf("%I64u\n",fib[b-1]); } } } return 0; }#include<stdio.h>
#define MAX 50
_int64 fib[MAX];
int main()
{
int n, a, b, i, len;
fib[0] = 1;
fib[1] = 1;
for(i = 2; i< MAX; i++)
fib[i] = fib[i-1] + fib[i-2];
while(scanf("%d",&n) != EOF)
{
for(i = 0; i < n; i++)
{
scanf("%d %d",&a,&b);
if(a == 1)
printf("%I64u\n",fib[b-1]);
else
{
len = a - 1;
b = b - len;
printf("%I64u\n",fib[b-1]);
}
}
}
return 0;
}