package basic.java; /**
* 不死神兔问题:
* 有一对兔子,从出生后第三个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,加入兔子都不死,问地二十个月的兔子对数是多少?
* 1
* 1
* 2
* 3
* 5
* 规律是从第三个月开始,每个月的兔子对数是前两个月的兔子对数之和。第一个月和第二个月的兔子对数是1,
*
* @author Administrator
*由于数据比较多所以定义数组来实现。
*int[] arr = new int[20];
*给数组的元素赋值
*arr[0] = 1;
*arr[1] = 1;
*找规律
*arr[2] = arr[0]+arr[1];
*arr[3] = arr[2]+arr[1];
*/
public class Test {
public static void main(String[] args) {
int[] arr = new int[20];
arr[0] = 1;
arr[1] = 1; for (int i = 2; i < arr.length; i++) {
arr[i] = arr[i-2] + arr[i-1];
}
System.out.println(arr[19]);
}
}
相关文章
- Ubuntu开机弹出错误“system program problem detected”的解决方法
- codeforces776D The Door Problem
- Error:Unable to start the daemon process. This problem might be caused by incorrect configuration of
- eclipse 错误信息 "File Search" has encounter a problem 解决
- 实验12:Problem C: 重载字符的加减法
- Problem E: 类的初体验(V)
- hdu4057 Rescue the Rabbit
- 【二分】Urozero Autumn Training Camp 2016 Day 5: NWERC-2016 Problem C. Careful Ascent
- Codeforces 1090M - The Pleasant Walk - [签到水题][2018-2019 Russia Open High School Programming Contest Problem M]
- Codeforces 1090D - Similar Arrays - [思维题][构造题][2018-2019 Russia Open High School Programming Contest Problem D]