㊗️:☀️☃️☃️☃️☀️ • 1个月前
#include<iostream>
using namespace std;
int n;
struct func {
int a, b, c;
}f[10001];
double value(double x) {
double ans = -1e18;
for (int i = 1; i <= n; i++) {
ans = max(f[i].a * x * x + f[i].b * x + f[i].c, ans);
}
return ans;
}
int main() {
int t;
cin >> t;
for (int a = 0; a < t; a++) {
cin >> n;
for (int i = 1; i <= n; i++) cin >> f[i].a >> f[i].b >> f[i].c;
double left = 0, right = 1000;
while (right - left > 1e-9) {
double lmid = (right - left) / 3 + left;
double rmid = right - (right - left) / 3;
if (value(lmid) > value(rmid)) {
left = lmid;
}
else {
right = rmid;
}
}
printf("%.4lf\n", value(left));
}
return 0;
}
评论:
请先登录,才能进行评论