中文题目就不解释什么乱七八糟的了
然后这道题如果你对数学很敏感可以用加权平均数算出来
这里提供一种二分的写法 这种写法需要注意精度问题
#include <iostream>
#include <cstring>
#include <cstdio>
#include <math.h>
using namespace std;
double eps = 1e-8;
double rate[105], sum;
int n ;
bool judge(double x)
{
double res = 0;
for (int i = 0; i < n; i ++) {
res += x / rate[i];
// if(res > sum) return false;
}
//printf("%lf %lf\n",x,res);
if(res >= sum) return true;
return false;
}
int main()
{
int _;
while (~scanf("%d",&n)) {
double Max = -1.0;
for (int i = 0; i < n; i ++) {
scanf("%lf",&rate[i]);
Max = max(Max , rate[i]);
}
scanf("%lf",&sum);
double l , r ;
l = 0.0, r = Max * sum;
while (r - l >= eps) {
double mid = (l + r) / 2.0;
// printf("%lf\n",mid);
if(judge(mid))
r = mid ;
else
l = mid ;
}
// for (double i = l; i <= l + 1.0; i += 0.01) {
// if(judge(i)){l = i;break;}
// }
printf("%.2lf\n",l);
}
}
/*
2
1 2
1000
5
0.1 2 3 4 5.5
1234
*/