zoukankan      html  css  js  c++  java
  • hdu2044java

    一只小蜜蜂...

    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];

    }

    }

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

     

  • 相关阅读:
    Building a ListBox with custom content in Silverlight 4.0
    asp.net通讯问题
    Using the NavigationService Object in SL4.0
    Creating a File Explorer for Isolated Storage
    图表ASP:Chart
    什么是继承?
    Java基础一笔带过
    Java多态
    自己动手写个小框架之七
    linux crontab 定时计划
  • 原文地址:https://www.cnblogs.com/1314wamm/p/5336766.html
Copyright © 2011-2022 走看看