人口预测基本 [英] population prediction basic

查看:66
本文介绍了人口预测基本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是当地一所大学的讲师,第一周我决定给我的学生一些入门级的脑筋急转弯。但令我惊讶的是,没有一个学生在没有我帮助的情况下写了一个正确的算法,所以在你的下方我会找到一个简短的我创建并且我很有兴趣看看其他人如何处理这个问题(不要显示代码我只是想看看你解决问题的方法)



brief:



写一个程序来预测虚构的外星人入侵中的生物数量。一个外星人每天放下X蛋,并且Y天后蛋孵化。

如果X是3而Y是5,那么有多少外星人

将在30天后出现单身外星人入侵?提示:制作一个数组/列表并使用每个插槽代表一天。

在第一个位置放一个1,然后计算放置的蛋数和孵化时间。将此值放在正确的单元格中,然后将当天的值添加到下一个并继续移动



不要将真实的世界逻辑应用于生物学这些创作只是回答问题!!!!!!!!!!

Im a cs lecturer at a local college and as its the first week i decided to give my students a bit of an entry level brain teaser.but to my surprise not a single student wrote a correct algorithm without my help so below you'll find a brief i created and im interested to see how other people would approach this issue (don't show code i just want to see your approach to the problem)

brief:

write a program to predict the number of creatures in a fictional alien invasion. An alien lays X egg each day and the eggs hatch after Y days.
If X is 3 and Y is 5, how many aliens
will there be 30 days after a single alien invades? Hint: make an array/list and use each slot to represent a day.
Put a 1 in the first position and then calculate how many eggs are laid and when they will hatch. Put this value in the correct cell and then add the value for the current day to the following one and move along

DON'T APPLY REAL WORLD LOGIC TO THE BIOLOGY OF THESE CREATURES JUST ANSWER THE QUESTION AS ITS WRITTEN!!!!!!!!!!

推荐答案

每隔五天人口乘以4 - 30天应该是六个生育周期 - 4 6 = 4096. 哎呀,再读一遍。





新算法:

从适当大小的数组开始。

单元格零值为1,其他为零。

使用循环迭代单元格一到三十。

每次迭代,添加上一个单元格的值到当前单元格,并将该值加到单元格的五个位置上的三个位置。



目前我有 167236 ,但可能存在栅栏贴错误。







除了JSOP将会到达并在此之前全部擦除它们。



我可能还会争辩说只有第一个外星人才是外星人,所有的孩子都在孵化这个星球是当地人。
Every five days the population multiplies by four -- thirty days should be six birth-cycles -- 46 = 4096 . Whoops, rereading again.


New algorithm:
Begin with an array of suitable size.
Cell zero has value one, all others are zero.
Use a loop to iterate cells one through thirty.
On each iteration, add the value of the previous cell to the current cell, and add that value times three to the cell five positions further on.

At the moment I have 167236, but there may be a fence-post error.



Except JSOP will arrive and wipe them all out before that happens.

I might also argue that only the first alien is an alien, all the children hatched on the planet are natives.


在我阅读了所有评论之后,我觉得很想试试这个基本问题。因此,如果我正确地理解了这个问题,那么生活在 n 的外国人的数量是前一天的外国人数量(没有人死亡)加上当天孵化的蛋的数量。后者等于在第n - 5 时产生的蛋的数量,这是在第nn-5天生活的外星人数的3倍。


所以我打开了我最喜欢的电子表格程序并在单元格0到4中放入1。在单元格5中,我放置了表达式



cell [n-1] + 3 * cell [n-5]



然后产生以下系列:



After I read all the comments I feel tempted to give this basic problem a try. So, if I understand the problem correctly, the number of aliens living on day n is the number of aliens of the previous day (nobody dies) plus the number of eggs that hatch on this day. The latter is equal to the number of eggs created on day n - 5, which is the 3 times the number of aliens that lived on day n - 5.

So I opened my favorite spread sheet program and put a 1 in cells 0 to 4. In cell 5 and following I placed the expression

cell[n-1] + 3*cell[n-5]

which then produces the following series:

day  aliens eggs
0	1	3
1	1	6
2	1	9
3	1	12
4	1	15
5	4	24
6	7	42
7	10	69
8	13	105
9	16	150
10	28	222
11	49	348
12	79	555
13	118	870
14	166	1.320
15	250	1.986
16	397	3.030
17	634	4.695
18	988	7.305
19	1.486	11.265
20	2.236	17.223
21	3.427	26.313
22	5.329	40.398
23	8.293	62.313
24	12.751	96.108
25	19.459	147.777
26	29.740	226.716
27	45.727	347.910
28	70.606	534.849
29	108.859	823.173
30	167.236	1.266.504



一旦问题的所有方面都被正确理解,这并不是那么难,甚至没有采用C ++程序来解决。还有一些细节仍然需要更好的规范,例如首先登陆的外星人,在登陆当天或第二天产生三个鸡蛋?或者,如果在某一天孵化出鸡蛋,我们是否计算这些卵孵化前后的外星人数?因此,作为一名学生,作为一名学生,我希望能够更准确地陈述问题而不是给出的问题。


That wasn't that hard and didn't even take a C++ program to solve, once all aspects of the problem were correctly understood. And there are a few details that still need better specification, e.g. does the alien who lands first, produce three eggs on the very day of his landing, or the day after? Or, if m eggs hatch on a particular day, do we count the number aliens before or after these eggs hatch? So, with all due respect, as a student I would hope for a more precise statement of a problem than the one given.


这是一个SQL Server递归公用表表达式:< br $>


Here's an SQL Server Recursive Common Table Expression to do it:

WITH cte AS
(
	SELECT -1 [Day] , 1 [Aliens] , 0 [+1] , 0 [+2] , 0 [+3] , 0 [+4] , 0 [+5] , 0 [Eggs]
UNION ALL
	SELECT [Day] + 1 , [Aliens] + [+1] , [+2] , [+3] , [+4] , [+5] , ( [Aliens] + [+1] ) * 3 ,  [+2] + [+3] + [+4] + [+5] + ( [Aliens] + [+1] ) * 3
	FROM cte
	WHERE [Day] < 30
)
SELECT * FROM cte


这篇关于人口预测基本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆