pid=5105" target="_blank" style="">题目链接:hdu 5105 Math Problem

题目大意:给定a。b,c,d。l,r。表示有一个函数f(x)=|a∗x3+b∗x2+c∗x+d|(L≤x≤R),求函数最大值。

解题思路:考虑极点就可以,将函数求导后得到f′(x)=0的x,即为极值点。在极值点处函数的单调性会发生变化,所以最大值一定就在区间边界和极值点上。注意a=0。b=0的情况,以及极值点不在区间上。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm> using namespace std; const double eps = 1e-9;
double A, B, C, D, L, R; double function(double x) {
if (x >= L && x <= R) {
double y = A * x * x * x + B * x * x + C * x + D;
return fabs(y);
}
return -1;
} double solve (double a, double b, double c) {
if (fabs(a) < eps) {
if (fabs(b) < eps)
return -1;
else
return function(- c / b);
} double dta = b * b - 4 * a * c;
if (dta > 0) {
dta = sqrt(dta);
return max(function( (-b + dta) / 2 / a ), function( (-b - dta) / 2 / a) );
}
return -1;
} int main () { while (~scanf("%lf%lf%lf%lf%lf%lf", &A, &B, &C, &D, &L, &R)) {
double ans = max(function(L), function(R));
ans = max(ans, solve(3*A, 2*B, C));
while (ans < 0);
printf("%.2lf\n", ans);
}
return 0;
}

hdu 5105 Math Problem(数学)的更多相关文章

  1. 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∗ ...

  2. HDU 5105 Math Problem

    让求  f(x)=|a∗x3+b∗x2+c∗x+d|(L≤x≤R)的最大值 这个题目讨论a和b的值,如果a==0的话,那么这个方程就变成了一个一元二次方程,直接找端点和对称轴(如果对称轴在给定的区间内 ...

  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. hdu5974 A Simple Math Problem(数学)

    题目链接 大意:给你两个数X,YX,YX,Y,让你找两个数a,ba,ba,b,满足a+b=X,lcm(a,b)=Ya+b=X,lcm(a,b)=Ya+b=X,lcm(a,b)=Y. 思路:枚举gcd( ...

  5. HDU 5858 Hard problem (数学推导)

    Hard problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5858 Description cjj is fun with ...

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

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

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

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

  8. 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 ...

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

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

随机推荐

  1. Selenium2+python自动化33-文件上传(send_keys)【转载】

    前言 文件上传是web页面上很常见的一个功能,自动化成功中操作起来却不是那么简单. 一般分两个场景:一种是input标签,这种可以用selenium提供的send_keys()方法轻松解决: 另外一种 ...

  2. (3)webApi postman使用

    https://www.getpostman.com/

  3. HDU1213 How Many Tables (并查集)

    题目大意: 有一个人要过生日了,请他的朋友来吃饭,但是他的朋友互相认识的才能坐在一起,朋友的编号从1 ~ n,输入的两个数代表着这两个人互相认识(如果1和2认识,2和3认识,那么1和3也就认识了).问 ...

  4. 模板—算法—整体二分(区间k小值)

    模板—算法—整体二分(区间k小值) Code: #include <cstdio> #include <algorithm> using namespace std; #def ...

  5. ubuntu 下终端关于调试C++的命令

    先确定安装了vim 和gcc (c语言)或者g++(c++) 如果没有安装可以在终端输入以下命令: sudo apt-get install build-essential sudo apt-get ...

  6. css sprite demo

    一张图片,用CSS分割成多个小图标. css样式: .icon{ background:url(../images/tabicons.png) no-repeat;width:18px; line-h ...

  7. JavaScript学习系列之执行上下文与变量对象篇

    一个热爱技术的菜鸟...用点滴的积累铸就明日的达人 正文 在上一篇文章中讲解了JavaScript内存模型,其中有提到执行上下文与变量对象的概念.对于JavaScript开发者来说,理解执行上下文与变 ...

  8. iOS开发之指定UIView的某几个角为圆角

    我们知道, 如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架).而若要指定某几个角(小于4)为圆角 ...

  9. jquery给input标签添加data-options属性

    //原生JS实现document.getElementById('startPrice').setAttribute("data-options", "required: ...

  10. 客户端连接Redis

    首先下载Jedis http://mvnrepository.com/artifact/redis.clients/jedis 然后脚本如下: package redistest; import ja ...