Error Curves

HDU  3714 Error Curves-LMLPHPHDU  3714 Error Curves-LMLPHP

思路:这个题的思路和上一个题的思路一样,但是这个题目卡精度,要在计算时,卡到1e-9。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 10100
#define eps 1e-9
using namespace std;
int T,n;
double ans;
double l,r,mid1,mid2;
double a[MAXN],b[MAXN],c[MAXN];
double f(double x){
ans=-0x7f7f7f7f;
for(int i=;i<=n;i++) ans=max(ans,x*x*a[i]+x*b[i]+c[i]);
return ans;
}
int main(){
scanf("%d",&T);
while(T--){
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%lf%lf%lf",&a[i],&b[i],&c[i]);
l=;r=;
while(r-l>eps){
mid1=(l+r)/;
mid2=(mid1+r)/;
if(f(mid1)>f(mid2)) l=mid1;
else r=mid2;
}
printf("%.4lf\n",f(l));
}
}
05-11 15:24