No rabbit death problem
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]);
}
}
No rabbit death problem的更多相关文章
- 围棋术语 & 中英文 。
https://senseis.xmp.net/?ChineseGoTerms 一字 二字 三字 四字 一字 长(nobi,solid extension),是指仅靠着自己的棋盘上已有棋子继续向前延伸 ...
- Unity 5 Game Optimization (Chris Dickinson 著)
1. Detecting Performance Issues 2. Scripting Strategies 3. The Benefits of Batching 4. Kickstart You ...
- 兔子问题(Rabbit problem)
Description 有一种兔子,出生后一个月就可以长大,然后再过一个月一对长大的兔子就可以生育一对小兔子且以后每个月都能生育一对.现在,我们有一对刚出生的这种兔子,那么,n 个月过后,我们会有多少 ...
- hdu----(1849)Rabbit and Grass(简单的尼姆博弈)
Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 5860 Death Sequence(死亡序列)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU-4057 Rescue the Rabbit(AC自动机+DP)
Rescue the Rabbit Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 1849(Rabbit and Grass) 尼姆博弈
Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 2016暑假多校联合---Death Sequence(递推、前向星)
原题链接 Problem Description You may heard of the Joseph Problem, the story comes from a Jewish historia ...
- HDU 4777 Rabbit Kingdom (2013杭州赛区1008题,预处理,树状数组)
Rabbit Kingdom Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
随机推荐
- Java NIO学习与记录(三): Scatter&Gather介绍及使用
Scatter&Gather介绍及使用 上一篇知道了Buffer的工作机制,以及FileChannel的简单用法,这一篇介绍下 Scatter&Gather 1.Scatter(分散 ...
- numpy.argmax()
numpy.argmax(a, axis=None, out=None) 返回沿轴axis最大值的索引 Parameters: a : array_like ...
- centos 7修改系统支持中文编码
2019-03-14 查看系统现支持编码 }[root@web dc2-user]#locale LANG=en_US.UTF- LC_CTYPE="en_US.UTF-8" LC ...
- CodeForces 1060 B Maximum Sum of Digits
Maximum Sum of Digits You are given a positive integer n. Let S(x)S(x) be sum of digits in base 10 r ...
- AutoDetectChangesEnabled及AddRange解决EF插入的性能问题
转自:http://www.cnblogs.com/nianming/archive/2013/06/07/3123103.html#2699851 记录下. 园友莱布尼茨写了一篇<Entity ...
- 微信授权获取code(微信支付)
摘要:最近在做h5支付,然后发现一个问题,微信自带浏览器不支持h5支付,然后后台又做了一个微信支付的接口,然后要传code参数,代码写好总结后,就发到这里记录一下: 因为有两个支付接口,所以首先判断打 ...
- 如何创建一个基于Node的HTTP服务器
首先创建一个HTTP服务器. var http = require('http'); function serve(request,response) { console.log(request.me ...
- i.mx6 Android5.1.1 初始化流程之init进程(未完成)
概述: 接在i.mx6 Android5.1.1 初始化流程之框架之后 参考资料:http://blog.csdn.net/mr_raptor/article/category/799879 相关源码 ...
- mysql 最小配置 及 安装
[mysqld] # 设置3306端口 port= # 设置mysql的安装目录 basedir=D:\-Installer\-MySQL\mysql--winx64 # 设置mysql数据库的数据的 ...
- Java中用双缓冲技术消除闪烁
在Java编写具有连贯变化的窗口程序时,通常的办法是在子类中覆盖父类的paint(Graphics)方法,在方法中使用GUI函数实现窗口重绘的过程.连贯变换的窗口会不断地调用update(Graphi ...