我是靠谱客的博主 瘦瘦奇迹,这篇文章主要介绍7-27 兔子繁衍问题-PTA(菜菜的方法),现在分享给大家,希望可以做个参考。

只列前七个月很难总结出规律来,因为第三个月的兔子对数变化规律还不明朗,直到列出了第八个月和第九个月,才能发现,自第三个月起:

  • 本月成熟= 上月成熟 + 上月两个月龄兔;
  • 本月一月龄兔 = 本月成熟;
  • 本月二月龄兔 = 上月成熟;

刚刚看了别的答案,才发现原来,每月的兔子数 = 前两个月兔子数相加(吐血)

以下代码可直接运行参考:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<stdio.h> /* a+b+c=population 1 1+0+0 2 1+0+0 3 1+1+0 4 1+1+1 5 2+2+1 6 3+3+2 7 5+5+3 8 8+8+5 9 13+13+8 10 21+21+13*/ int main(){ int N,month = 0,population = 0,one_month,two_month,mature = 1, last_two_mon = 0,bottle; scanf("%d",&N); printf("ttmaturettone_monthttwo_monthn");//打印出三个月以后兔子的数量变化 printf("tt成熟兔子t一月龄兔子t二月龄兔子n");//打印出三个月以后兔子的数量变化 while(population < N){ ++month; if(month >3){ bottle = mature; mature = last_two_mon + mature; one_month = mature; two_month = bottle; last_two_mon = two_month; population = mature + one_month + two_month; printf("%d月:tt%dtt%dtt%dn",month,mature,one_month,two_month);//打印出三个月以后兔子的数量变化 }else if(month == 3){ population = 2; }else{ population = 1; } } printf("n兔子达到%d对需要%d个月n",N,month); return 0; }

最后

以上就是瘦瘦奇迹最近收集整理的关于7-27 兔子繁衍问题-PTA(菜菜的方法)的全部内容,更多相关7-27内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部