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 ...
随机推荐
- java中处理http连接超时的方法
声明一个boolean公共变量,表明当前httpconnection是否得到服务器回应. 你的连接线程中在连接之前置这个变量为false; 另起一个监视线程,拿到那个HttpConnection的连接 ...
- php开发入门教程
LAMP window:WAMP(windows,apache,mysql,php) LAMP是 Linux,Apache,MySQL和PHP的缩写,是我们提供 Web 服务的软件基础. 对于 Lin ...
- codevs 4163 hzwer与逆序对
传送门 题目描述 Description hzwer在研究逆序对. 对于数列{a},如果有序数对(I,j)满足:i<j,a[i]>a[j],则(i,j)是一对逆序对. 给定一个数列{a}, ...
- linux中bin和xbin下可执行程序的区别
/bin下的都是Linux最基础的,所有用户都可以使用的外部命令 /sbin下的都是只有超级用户root才能使用的.管理Linux系统的外部命令 /usr/bin以及/usr/local/bin下的都 ...
- python 单元测试
http://blog.csdn.net/five3/article/details/7104466
- BZOJ 1070 修车
Description 同一时刻有\(N\)位车主带着他们的爱车来到了汽车维修中心.维修中心共有\(M\)位技术人员,不同的技术人员对不同的车进行维修所用的时间是不同的.现在需要安排这\(M\)位技术 ...
- JAVA线程示范之一种
线程有两种方法生成,这是其中的一种.. MyRunnable.java public class MyRunnable implements Runnable { public void run() ...
- java学习之数组(一)【内存】
在java语言当中,为了更方便多个数据的管理,这里提供数组. 比如说,现在我们有一组数据,7,8,9,9,为了保存这四个数据,我们分别要定义变量来保存,少了还好说.但是假如,有100多个数据呢,我们一 ...
- jdbc.properties 包含多种数据库驱动链接的版本。
# Properties file with JDBC-related settings. ########## # HSQLDB # ########## #jdbc.driverClassName ...
- 数据结构(KD树):HDU 4347 The Closest M Points
The Closest M Points Time Limit: 16000/8000 MS (Java/Others) Memory Limit: 98304/98304 K (Java/Ot ...