让求  f(x)=|a∗x3+b∗x2+c∗x+d|(L≤x≤R)的最大值

这个题目讨论a和b的值,如果a==0的话,那么这个方程就变成了一个一元二次方程,直接找端点和对称轴(如果对称轴在给定的区间内)处的函数值就行,如果a != 0,那么求导,求导之后判断二次方程的delta,如果delta小于等于0,说明是单调的,那么最值还是端点处取到,如果delta大于0, 那么就要比较两个极点(如果极点在给定的区间内)处的值和端点值的大小就行了。

/*************************************************************************
> File Name: math.cpp
> Author: Howe_Young
> Mail: 1013410795@qq.com
> Created Time: 2015年09月14日 星期一 20时18分44秒
************************************************************************/ #include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm> using namespace std;
typedef long long ll;
double a, b, c, d, L, R;
const double eps = 1e-;
double func(double x)
{
return fabs(a * x * x * x + b * x * x + c * x + d);
}
int sgn(double x)
{
if (fabs(x) < eps) return ;
return x > ? : -;
}
int main()
{
while (~scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &L, &R))
{
double ans = max(func(L), func(R));
if (a == )
{
if (b != )
{
double t = -c / 2.0 / b;
if (sgn(t - L) > && sgn(t - R) < )
ans = max(ans, func(t));
}
}
else
{
double delta = * b * b - * a * c;
if (delta > )
{
double x1 = (-2.0 * b - sqrt(delta)) / 6.0 / a;
double x2 = (-2.0 * b + sqrt(delta)) / 6.0 / a;
if (sgn(x1 - L) >= && sgn(x1 - R) <= )
ans = max(ans, func(x1));
if (sgn(x2 - L) >= && sgn(x2 - R) <= )
ans = max(ans, func(x2));
}
}
printf("%.2lf\n", ans);
}
return ;
}

HDU 5105 Math Problem的更多相关文章

  1. hdu 5105 Math Problem(数学)

    pid=5105" target="_blank" style="">题目链接:hdu 5105 Math Problem 题目大意:给定a.b ...

  2. HDU 5105 Math Problem --数学,求导

    官方题解: f(x)=|a∗x3+b∗x2+c∗x+d|, 求最大值.令g(x)=a∗x3+b∗x2+c∗x+d,f(x)的最大值即为g(x)的正最大值,或者是负最小值.a!=0时, g′(x)=3∗ ...

  3. hdu 6182A Math Problem(快速幂)

    You are given a positive integer n, please count how many positive integers k satisfy kk≤nkk≤n.  Inp ...

  4. HDU 5055 Bob and math problem(结构体)

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5055 Problem Description Recently, Bob has been think ...

  5. [HDU - 5170GTY's math problem 数的精度类

    题目链接:HDU - 5170GTY's math problem 题目描述 Description GTY is a GodBull who will get an Au in NOI . To h ...

  6. HDU 1757 A Simple Math Problem 【矩阵经典7 构造矩阵递推式】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1757 A Simple Math Problem Time Limit: 3000/1000 MS (J ...

  7. hdu 1757 A Simple Math Problem (乘法矩阵)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  8. HDU 5615 Jam's math problem

    Jam's math problem Problem Description Jam has a math problem. He just learned factorization.He is t ...

  9. BestCoder Round #70 Jam's math problem(hdu 5615)

    Problem Description Jam has a math problem. He just learned factorization. He is trying to factorize ...

随机推荐

  1. phpcms 如何获取文章

    请求地址http://127.0.0.1/phpcms/index.php?m=content&c=index&a=show&catid=6&id=8 先来判断地址对应 ...

  2. 香港house of hello品牌包包是怎样被模仿呢?

    今天,作为女性的朋友来说,house of hello包包可能对大家都不会陌生吧,特别是一些白领阶层的女性同胞们,这个品牌比较熟悉,现在,也有网友称,这个是恶搞包包.house of hello包包原 ...

  3. Pair of Numbers

    Codeforces Round #209 (Div. 2) D:http://codeforces.com/contest/359/problem/D 题意:给以一个n个数的序列,然后问你最大的区间 ...

  4. Task schedule

    hdu4907:http://acm.hdu.edu.cn/showproblem.php?pid=4907 题意:中文题. 题解:这一道水题,自己调了很久,并且没有注意到序列可能是乱序的,wa了好几 ...

  5. Transformation

    hdu4578:http://acm.hdu.edu.cn/showproblem.php?pid=4578 题意:给一个序列 {an},有 4 种操作.1.将一段区间的数全部加 c.2.将一段区间的 ...

  6. struts配置时遇到的几个问题

    1. struts在配置文件的时候,如果package包继承为 :extends="json-default" ,那么项目中要引入struts2-json-plugin-xxx.j ...

  7. /dev/random和/dev/urandom的一点备忘

    1.  基本介绍 /dev/random和/dev/urandom是Linux系统中提供的随机伪设备,这两个设备的任务,是提供永不为空的随机字节数据流.很多解密程序与安全应用程序(如SSH Keys, ...

  8. linux下so动态库一些不为人知的秘密(转)

    linux 下有动态库和静态库,动态库以.so为扩展名,静态库以.a为扩展名.二者都使用广泛.本文主要讲动态库方面知识.基本上每一个linux 程序都至少会有一个动态库,查看某个程序使用了那些动态库, ...

  9. ZOJ 3469 Food Delivery

    题目大意: 有n个人,住在一条直线上.第i个人的坐标是Xi,街上有个外卖餐馆的位置是X,现在餐厅工作人员要给街上的每个人送饭,送完之后再回到餐厅,送饭人的速度是V,每个人有个不满意值,当这个人送餐时间 ...

  10. datagridview,textbox,combobox的数据绑定,数据赋值,picturebox的用法

    一:datagridview数据绑定 二:textbox的数据绑定(datetimepicker) 总结: 最好还是写成双向绑定那种,不要再写出发事件了,只要在给textbox赋值就能重新绑定了,不然 ...