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);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值