(Miku)[https://loj.ac/problem/10013]
画个图就知道,f(x)还是个单峰函数
三分起
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
double xz=1e-9;
int t,n;
double l,r;
double lm,rm;
double a[100005],b[100005],c[100005];
double ans;
double cou(double x){
ans=-0x7fffffff;
for(int i=1;i<=n;++i){
ans=max(ans,a[i]*x*x+b[i]*x+c[i]);
}
return ans;
}
double sf(double l,double r){
while(l+xz<r){
lm=l+(r-l)*0.3;
rm=l+(r-l)*0.7;
if(cou(lm)<cou(rm)){
r=rm;
}else{
l=lm;
}
}
return cou(l);
}
int main(){
scanf("%d",&t);
for(int i=1;i<=t;++i){
scanf("%d",&n);
for(int j=1;j<=n;++j){
scanf("%lf%lf%lf",&a[j],&b[j],&c[j]);
}
printf("%.4lf
",sf(0.0,1000.0));
}
return 0;
}