链接:Miku
三分法的模板,和是一个东西
对于修正量的精度要求极高
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
double a[100001],b[100001],c[100001];
int t;
int n;
double l,r;
double xiu=1e-9;
double ch(double x){
double ans=-0x7fff77ff;
double l=0;
for(int i=1;i<=n;++i){
ans=max(ans,(double)x*x*a[i]+x*b[i]+c[i]);
}
return ans;
}
int main(){
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%lf%lf%lf",&a[i],&b[i],&c[i]);
}
l=0.0;
r=1000.0;
while(l+xiu<r){
// cout<<l<<" "<<r<<endl;
double lm=l+(r-l)*0.3;
double rm=l+(r-l)*0.7;
if(ch(lm)<ch(rm)){
r=rm;
}else
l=lm;
}
printf("%.4lf
",ch(l));
}
return 0;
}