当前位置:网站首页>Uva5009 error curves three points

Uva5009 error curves three points

2022-06-26 13:11:00 YJEthan

The question : Find the minimum value of the maximum value of some concave functions with openings upward ( If you don't understand, read it carefully twice )

analysis : The minimum value of the maximum value of some concave functions with an upward opening is still a concave function

Finding the maximum value of the concave convex function obviously uses three points . See the code for details. , Similar to dichotomy , It's just two points in the middle , Function that doesn't understand , Draw more pictures and you can write them .

#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int n,a[10002],b[10002],c[10002];
double m1,m2,l,r,ans;
double solve(double x)
{
    int i=0;
    double cont=a[0]*x*x+b[0]*x+c[0];
    for(i=1;i<n;i++)
       cont=max(cont,a[i]*x*x+b[i]*x+c[i]);
    return cont;
}
int main()
{
    int t,i;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(i=0;i<n;i++)
        {
            scanf("%d%d%d",&a[i],&b[i],&c[i]);
        }
        l=0.0;r=1000.0;
        for(i=0;i<100;i++)
        {
            m1=(l+r)/2.0;
            m2=(m1+l)/2.0;
            if(solve(m1)>solve(m2))
            {
                r=m1;
            }
            else l=m2;
        }
        ans=(l+r)/2.0;
        printf("%.4lf\n",solve(ans));
    }
    return 0;
}




原网站

版权声明
本文为[YJEthan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206261223286383.html