首页 > 其他 > 详细

uva 1476(三分)

时间:2017-08-27 11:42:16      阅读:235      评论:0      收藏:0      [点我收藏+]

三分求一堆最大值中的最小

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=10000+100;
const int inf=0x3f3f3f3f;
double a[maxn],b[maxn],c[maxn];
int t,n;
double f(double x)
{
       double maxi=a[1]*x*x+b[1]*x+c[1];
     for(int i=2;i<=n;i++)
     {
        double mm=a[i]*x*x+b[i]*x+c[i];
         maxi=max(maxi,mm);
     }
      return maxi;
}
double sanfen(double l,double r)
{
    while(r-l>1e-10)
    {
        double p=l+(r-l)/3.0;
        double q=r-(r-l)/3.0;
      if(f(p)<=f(q))
        r=q;
      else l=p;
    }
    return l;
}
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]);
            double x=sanfen(0,1000.0);
           printf("%.4lf\n",f(x));
      }
    return 0;
}

 

uva 1476(三分)

原文:http://www.cnblogs.com/Wangwanxiang/p/7439850.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!