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
可以说是长跪不起,能爬向右侧相邻的蜂房
完全忽视了这句话……导致程序一直找不到错误出在什么地方!!!
#include<iostream>
#include<stdio.h>
using namespace std ;
int main() {
_int64 a[60] = { 0 , 0 , 1 , 2 , 3 } ;
int n ;
while( cin >> n ) {
while( n-- ) {
int x , y ;
cin >> x >> y ;
if( x > y ) {
x = x ^ y ;
y = x ^ y ;
x = x ^ y ;
}
int t = y - x + 1 ;
for( int i = 5 ; i <= t ; i++ )
a[i] = a[i-2] + a[i-1] ;
printf("%I64d\n",a[t]);
}
}
return 0 ;
}
如果是从大到小 不应该把大小调换啊!正确程序如下:
#include<iostream>
#include<stdio.h>
using namespace std ;
int main() {
_int64 a[60] = { 0 , 0 , 1 , 2 , 3 } ;
int n ;
while( cin >> n ) {
while( n-- ) {
int x , y ;
cin >> x >> y ;
int t = y - x + 1 ;
for( int i = 5 ; i <= t ; i++ )
a[i] = a[i-2] + a[i-1] ;
printf("%I64d\n",a[t]);
}
}
return 0 ;
}
尼玛 , 以后看题要细心啊!不然得不偿失啊!!!