题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3714
懂了三分思想和F(x)函数的单调性质,这题也就是水题了
#include "stdio.h" //最后得到的F(x)函数要么是单调的,要么是先减后增的,有了这个性质,就可以三分了~
#include "string.h"
#define N 10005
#define eps 1e-9
#define INF 0x3fffffff
struct node
{
int a;
int b;
int c;
}q[N];
int n;
double S(double x)
{
double sx;
double maxt = -INF;
for(int i=0; i<n; ++i)
{
sx = q[i].a*x*x+q[i].b*x+q[i].c;
if(sx>maxt)
maxt = sx;
}
return maxt;
}
int main()
{
int i,T;
double ans_mid,ans_mid_mid;
double left,right,mid,mid_mid;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=0; i<n; ++i)
scanf("%d %d %d",&q[i].a,&q[i].b,&q[i].c);
left = 0;
right = 1000;
while(right-left>eps)
{
mid = (right+left)/2;
ans_mid = S(mid);
mid_mid = (mid+right)/2;
ans_mid_mid = S(mid_mid);
if(ans_mid>ans_mid_mid)
left = mid;
else
right= mid_mid;
}
printf("%.4lf\n",S(right));
}
}