题意
假设地球上的新生资源按恒定速度增长。照此测算,地球上现有资源加上新生资源可供 亿人生活 年,或供 亿人生活 年。
求地球资源一年增加量为多少。
思路
我们可以设地球现有资源为 ,一年增加量为 。
由题意得:
两式相减得:,
即:
用 fixed setprecision 保留 位小数。
代码
#include <bits/stdc++.h>
using namespace std;
int x, a, y, b;
int main() {
cin >> x >> a >> y >> b;
cout << fixed << setprecision(2) << (double)(x * a - y * b) / (a - b) << endl; // 计算答案
return 0;
}