Growth of a Population
来源:互联网 发布:翅片式换热器计算软件 编辑:程序博客网 时间:2024/05/20 21:59
一、问题描述
在一个小镇,人口在一年初是p0 = 1000。 人口每年定期增加2%,此外每年有50个新居民生活在城里。 城市需要多少年才能看到其人口大于或等于p = 1200居民?
At the end of the first year there will be: 1000 + 1000 * 0.02 + 50 => 1070 inhabitantsAt the end of the 2nd year there will be: 1070 + 1070 * 0.02 + 50 => 1141 inhabitants (number of inhabitants is an integer)At the end of the 3rd year there will be:1141 + 1141 * 0.02 + 50 => 1213It will need 3 entire years.
More generally given parameters:
p0, (一年之初的人口数)percent, (每年的人口增长率)aug (每年离开或者新定居的居民), p (超越的人口数,作对比用)aug是 int 型的数(> 0),percent 为positive or null floating number,p0和p是正整数(> 0)函数nb_year应该返回整数 n ,以获得大于或等于p的总体数。
Note: 不要忘记在函数体中将参数 percent 转换为百分比:如果参数percent为2,则必须将其转换为0.02。
解决方案
class Arge { public static int nbYear(int p0, double percent, int aug, int p) { int n=0; while(p0<p){ p0 = (int)(p0 + 0.01 * percent * p0 + aug); n++; } return n; }}
0 0
- Growth of a Population
- [Haskell] CodeWars|Growth of a Population
- 世界人口增长预测(World Population Growth)
- American History---Growth of a Nation
- IELTS12 Test6 the population of some countries include a relatively large number of young adults
- Statistics Distribution Of Normal Population
- Chapter3 Growth of Functions
- A New Growth Industry
- The Growth Markets of China
- zoj1051 A New Growth Industry
- ZOJ1051 A New Growth Industry
- JOJ1086: A New Growth Industry
- ZOJ1051 A New Growth Industry
- ZOJ1051 A New Growth Industry
- Zoj1051 A New Growth Industry
- The problems caused by the excess of population
- growth
- Week1-9Order-of-Growth classifications
- Home键的广播监听
- java 并发概念与内存分析,原子性、可见性、有序性
- final修饰符
- CodeForces 136A Presents
- php类面向对象学习笔记
- Growth of a Population
- 在慕课上学习的,HTML和CSS基础学习笔记6
- javascript 学习1
- 41、检查重复字符串
- 图论 [未完成 待续~待修改]
- 开源框架(android)
- C++调用Python浅析
- javascript的函数
- ubuntu 16.04 启用root用户方法