hdu 3714 三分

#include<stdio.h>
#define  mi  1e-9
#define N 11000
struct node{
double x,y,z;
}a[N];
int n;
double Max(double a,double b) {
return a>b?a:b;
}
double ff(double h) {
    double ma=-111111111;
    int i;
    for(i=1;i<=n;i++)
        ma=Max(ma,a[i].x*h*h+a[i].y*h+a[i].z);
    return ma;
}
double midd() {
   double start,end,mid,midd;
   start=0.0;
   end=1000.0;
   while(end-start>mi) {
    mid=(start+end)/2;
    midd=(mid+end)/2;
    if(ff(mid)>ff(midd))
        start=mid;
    else
        end=midd;
   }
   return ff(end);
}
int main() {
   int t,i;
   scanf("%d",&t);
   while(t--) {
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%lf%lf%lf",&a[i].x,&a[i].y,&a[i].z);
    printf("%.4f\n",midd());
   }
return 0;
}
posted @ 2014-05-08 11:34  HYDhyd  阅读(128)  评论(0编辑  收藏  举报