输入W Y x N
输出第N年后的平均年龄
5 5 0.2 3
15
#include <iostream> #include <cmath> using namespace std; void AverageAge() { // 总人数为W,平均年龄为Y岁 // 每年离职率为x,x>0&&x<1 double W, Y, x, N; while(cin >> W >> Y >> x >> N) { while(N--) { Y = 21 * x + (1 - x) * (Y + 1); } cout << ceil(Y) << endl; } } int main() { AverageAge(); return 0; }
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题