随笔分类 -  算法设计

The Tower of Hanoi
摘要:The Tower of Hanoi consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.The objective of the puzzle is to move the en 阅读全文
posted @ 2012-06-06 23:12 YoVinci 阅读(396) 评论(0) 推荐(0)
兔子繁殖问题
摘要:问题描述:一对兔子从出生后第三个月开始,每月生一对小兔子。小兔子到第三个月又开始生下一代小兔子。假若兔子只生不死,一月份抱来一对刚出生的小兔子,问一年中每个月各有多少只兔子。问题分析:1月2月3月4月5月6月。。。111+1=22+1=33+1+1=55+1+1+1=8。。。如上面表格数据可以看出第三个月以后兔子的对数是前两个月兔子对数的和。算法设计:用a,b分别表示每月前2个月和前1个月的兔子对数,第1和第2个月的兔子数作为初值都为1,第3个月的兔子数为c=a+b。求第4个月的兔子数时,将第4个月的前2个月和前1个月的兔子对数分别存储在a,b中,即a=b,b=c,构造循环不变式。java代码 阅读全文
posted @ 2012-06-05 23:22 YoVinci 阅读(2271) 评论(1) 推荐(1)