一只小蜜蜂...

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 57675 Accepted Submission(s):
20836

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.*;
class Main{
public static void main(String args[])
{Scanner cin=new Scanner(System.in);
while(cin.hasNext())
{int n=cin.nextInt();
while(n-->0)
{int a=cin.nextInt();
int b=cin.nextInt();
int c=0;
c=b-a;
System.out.println(sum(c));
}
}
}
public static long sum(int s)
{long []a=new long[51];
a[0]=1;a[1]=1;
for(int i=2;i<51;i++)
{a[i]=a[i-1]+a[i-2];
}
return a[s];

}

}

这是一个推理题,相邻的蜂窝有两个,所以就是前两个蜂窝之和;

hdu2044java的更多相关文章

  1. hdu2044java递推

    一只小蜜蜂... Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

随机推荐

  1. UNIX网络编程——套接字选项

    http://www.educity.cn/linux/1241288.html 有时候我们需要控制套接字的行为(如修改缓冲区的大小),这个时候我们就要学习套接字选项. int getsockopt( ...

  2. paip.php eclipse output echo 乱码

    paip.php eclipse output echo 乱码 作者Attilax ,  EMAIL:1466519819@qq.com  来源:attilax的专栏 地址:http://blog.c ...

  3. while +next 循环 回到循环顶端

    my $show_tip = 1; sub login { while (1) { my $api ="https://login.weixin.qq.com/cgi-bin/mmwebwx ...

  4. 17.1.1.7 Setting Up Replication with New Master and Slaves 设置复制使用新的master和slaves:

    17.1.1.7 Setting Up Replication with New Master and Slaves 设置复制使用新的master和slaves: 最简单和最直接方式是设置复制使用新的 ...

  5. 从tcp原理角度理解Broken pipe和Connection reset by peer的区别

    从tcp原理角度理解Broken pipe和Connection reset by peer的区别 http://lovestblog.cn/blog/2014/05/20/tcp-broken-pi ...

  6. BZOJ1510: [POI2006]Kra-The Disks

    1510: [POI2006]Kra-The Disks Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 265  Solved: 157[Submit][ ...

  7. JAVA 数组常用技巧

    1.  在Java中输出一个数组(Print an array in Java) int[] intArray = { 1, 2, 3, 4, 5 }; String intArrayString = ...

  8. 日常工作中使用的一些Mongodb语句

    .通过_userID字段查询重复录入内容 > db.template.aggregate({}}},{$}}) .查询 db.template.find({"group_7ee1247 ...

  9. ECSHOP首页调用指定分类下的商品

    转:http://bbs.ecshop.com/thread-1123207-1-1.html 调用某个分类下的商品,方法有很多种的,不过都需要先在后台设置模板那里设置显示和显示条数, 然后在需要调用 ...

  10. Javascript 母羊生小羊问题,递归

    农场买了一只小羊,这种羊在第一年是小羊,第二年的年底会生一只小羊,第三年不生小羊,第四年的年底还会再生下一只小羊,第五年就死掉了. 要计算N年时农场里有几只羊. [凡是碰到“一生二.二生三.三生万物” ...