HDU 5105 Math Problem
让求 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的更多相关文章
- hdu 5105 Math Problem(数学)
pid=5105" target="_blank" style="">题目链接:hdu 5105 Math Problem 题目大意:给定a.b ...
- 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∗ ...
- hdu 6182A Math Problem(快速幂)
You are given a positive integer n, please count how many positive integers k satisfy kk≤nkk≤n. Inp ...
- HDU 5055 Bob and math problem(结构体)
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5055 Problem Description Recently, Bob has been think ...
- [HDU - 5170GTY's math problem 数的精度类
题目链接:HDU - 5170GTY's math problem 题目描述 Description GTY is a GodBull who will get an Au in NOI . To h ...
- 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 ...
- hdu 1757 A Simple Math Problem (乘法矩阵)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU 5615 Jam's math problem
Jam's math problem Problem Description Jam has a math problem. He just learned factorization.He is t ...
- 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 ...
随机推荐
- div浮动框居于浏览器窗口中间
代码先贴这里,随后再改 <script language="JavaScript"> document.getElementById('divCenter').styl ...
- sphinx (coreseek)——3、区段查询 与 增量索引实例
首先本文测试数据100多万的域名的wwwtitle 信息 检索数据: 首先建立临时表格: CREATE TABLE `sph_counter` ( `index_id` ) NOT NULL, `m ...
- 升级Python至2.7.8,并安装django
1:下载Python-2.7.8.tgz2:步骤:tar -zxvf Python-2.7.8.tgzcd Python-2.7.8./configure -h --查看configure选项./co ...
- windows phone 8学习 - 选择器
1照相机 CameraCaptureTask cct=new CameraCaptureTask(); cct.Completed+=new EventHandler<PhotoResult&g ...
- mapreduce (四) MapReduce实现Grep+sort
1.txt dong xi cheng xi dong cheng wo ai beijing tian an men qiche dong dong dong 2.txt dong xi cheng ...
- cut 命令
今天看到cut拿来取参数也是很方便的. cut -d = -f 2 -d表示分隔符 -f参数是分隔符算第几个参数
- vs2012 aps.net4.0/4.5尚未在web服务器上注册
安装了vs2015后,vs2012 启动后报错: aps.net4.0/4.5尚未在web服务器上注册 解决办法: 下载微软补丁: http://blogs.msdn.com/b/webdev/arc ...
- Qt Creator Valgrind内存分析前端(分析Nginx内存)
Linux上使用Qt Creator进行C/C++开发http://my.oschina.net/eechen/blog/166969Qt Creator GDB调试前端(调试Nginx):http: ...
- 调试中除了在URL上加时间戳外,如何避免js、css被返回304状态?
在本地开发环境(nginx)中,经常遇到这样的情况:调试js时浏览器总是不载入已修改的js内容,而直接吐出了上次缓存的代码. 我曾经做过以下尝试: ctrl+F5 ctrl+F5+F5+F5+F5 ...
- HDOJ(HDU) 2304 Electrical Outlets(求和、、)
Problem Description Roy has just moved into a new apartment. Well, actually the apartment itself is ...