HDU - 5105 Math Problem

高中数学问题。不过学会了一个技巧,对于精度要求小的,可以暴力......


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
const double EPS=1e-10;
double a, b, c, d, l, r;
double fun(double x)
{
    return fabs(a*x*x*x+b*x*x+c*x+d);
}
//int main()
//{
//    while(~scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &l, &r))
//    {
//        double ans=0;
//        for(int i=0; i<=300000; i++)
//            ans=max(ans, fun(l+(r-l)*i/300000.0));
//        printf("%.2lf\n", ans);
//    }
//    return 0;
//}
int main()
{
    while(~scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &l, &r))
    {
        double ans=max(fun(l), fun(r));
        double A=3.0*a, B=2.0*b, C=c;
        if(fabs(A)<EPS)
        {
            if(fabs(B)>EPS)
            {
                double x=-C/B;
                if(l<x && x<r)
                    ans=max(ans, fun(x));
            }
        }
        else
        {
            double delt=B*B-4.0*A*C;
            if(fabs(delt)>EPS)
            {
                double x1=(-B+sqrt(delt))/(2.0*A), x2=(-B-sqrt(delt))/(2.0*A);
                if(l<=x1 && x1<=r)
                    ans=max(ans, fun(x1));
                if(l<=x2 && x2<=r)
                    ans=max(ans, fun(x2));
            }
        }
        printf("%.2lf\n", ans);
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值