题目
P1883-函数(每个点的值为取对应多个正抛物线的值中的最大值,求区间最小值)
输入样例#1:
2
1
2 0 0
2
2 0 0
2 -4 2

输出样例#1:
0.0000
0.5000

【数据范围】T < 10, n ≤ 10000,0 ≤ a ≤ 100,|b| ≤ 5000, |c| ≤ 5000

思路:画出多个正抛物线,就能看出来了,最后的取值曲线是凸型曲线。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define en '\n'
#define eps 1e-10
using namespace std;
typedef double du;
const int INF=1e9,N=1e4+5;
struct qx{du a,b,c;}q[N];
int n;
du work(du x)
{
    du res=-INF;
    for(int i=1;i<=n;i++)
        res=max(res,q[i].a*x*x+q[i].b*x+q[i].c);
    return res;
}
int main()
{
    int T;scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%lf%lf%lf",&q[i].a,&q[i].b,&q[i].c);
        du l=0,r=1000,m1,m2,ans;
        while(r-l>eps)
        {
            m1=(l+r)/2,m2=(m1+r)/2;
            if(work(m1)>(ans=work(m2)))
                l=m1;
            else
                r=m2;
        }
        printf("%.4f\n",ans);
    }
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
  • 2022-12-23
  • 2021-07-03
  • 2021-09-01
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-04
  • 2021-11-01
  • 2021-12-27
  • 2021-10-20
相关资源
相似解决方案