hdu 3714

三分法求下凸函数的最小值,可知,max(下凸函数,下凸函数)得到的函数认为下凸函数

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 using namespace std;
 5 const int maxn=10000+10;
 6 double a[maxn],b[maxn],c[maxn];
 7 int n;
 8 double solve(double x)
 9 {
10     double maxv=a[0]*x*x+b[0]*x+c[0];
11     for(int i=0;i<n;i++) maxv=max(maxv,a[i]*x*x+b[i]*x+c[i]);
12     return maxv;
13 }
14 int main()
15 {
16     int t;
17     cin>>t;
18     while(t--)
19     {
20         int i;
21         scanf("%d",&n);
22         for(i=0;i<n;i++) scanf("%lf%lf%lf",&a[i],&b[i],&c[i]);
23         double l=0.0,r=1000.0,m1,m2;
24         double a1,a2;
25         for(i=0;i<100;i++)
26         {
27             m1=l+(r-l)/3;
28             m2=r-(r-l)/3;
29             if(solve(m1)<solve(m2)) r=m2;
30             else l=m1;
31         }
32         printf("%.4lf\n",solve(l));
33     }
34     return 0;
35 }
原文地址:https://www.cnblogs.com/lj030/p/3093615.html