您的位置:首页 > 其它

HDOJ 2044 一只小蜜蜂...

2016-01-24 23:33 211 查看
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

import java.util.Scanner;

public class Main {
static long[] time1 = new long[50];

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Times();
int n = sc.nextInt();

while (n-- > 0) {

int a = sc.nextInt();
int b = sc.nextInt();

System.out.println(time1[b - a]);

}
}

private static void Times() {
time1[1] = 1;
time1[2] = 2;
time1[3] = 3;
for (int i = 4; i < 50; i++) {
time1[i] = time1[i - 1] + time1[i - 2];
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: