SDUT-1218 养兔子(JAVA*)

版权声明:欢迎转载,也请注明原文地址 https://blog.csdn.net/wzy_2017/article/details/80018564

养兔子

Time Limit: 1000 ms  Memory Limit: 65536 KiB

Problem Description

一对成熟的兔子每天能且只能产下一对小兔子,每次都生一公一母,每只小兔子的成熟期是1天,小兔子出生后隔一天才能再生小兔子。第一天某人领养了一对成熟的兔子,一公一母,请问第N天以后,他将会得到多少对兔子。

Input

测试数据包括多组,每组一行,为整数n(1≤n≤90)。
输入以0结束。

Output

对应输出第n天有几对兔子(假设没有兔子死亡现象,而且是一夫一妻制)。

Sample Input

1
2
0

Sample Output

1
2

Hint

数据类型可以用64位整数:long long

Source

majia


import java.util.*;

public class Main {

	static long a[] = new long[91];
    static void init()
    {
    	a[1]=1;
    	a[2]=2;
    	for(int i=3;i<=90;i++)
    		a[i]=a[i-1]+a[i-2];
    }
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		init();
		while(cin.hasNextLine())
		{
			int ans=cin.nextInt();
			if(ans==0)
				break;
			else
			System.out.println(a[ans]);
		}
		cin.close();
	}
}

猜你喜欢

转载自blog.csdn.net/wzy_2017/article/details/80018564