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 |
Accepted----------
View Code
1 #include <stdio.h> 2 int main() 3 { 4 int n, a, b, i; 5 _int64 f[55] = {0, 1, 2}; 6 for (i = 3; i < 51; i++) 7 f[i] = f[i - 2] + f[i - 1]; 8 scanf("%d", &n); 9 while (n--) 10 { 11 scanf("%d %d", &a, &b); 12 printf("%I64d\n", f[b - a]); 13 } 14 return 0; 15 }
f(n) = f(n - 1) + f(n - 2)
Wrong------------
View Code
1 #include <stdio.h> 2 int main() 3 { 4 int n, a, b, length, result; 5 scanf("%d", &n); 6 while (n--) 7 { 8 scanf("%d %d", &a, &b); 9 length = (b + 1) / 2 - (a + 1) / 2 + 1; 10 if (a % 2 == b % 2) 11 result = a - b; 12 else if (a % 2 < b % 2) 13 result = 0; 14 else if (a == 1) 15 result = length; 16 else 17 result = 2 * length; 18 printf("%d\n", result); 19 } 20 return 0; 21 }
According to "蜜蜂只能爬向右侧相邻的蜂房", so I get the above program. But it's wrong, did I misunderstand?