让求  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. Ubuntu phpmyadmin 缺少mcrypt扩展解决方法

    之前在登陆phpmyadmin的时候,会出现警告说缺少mcrypt扩展的错误,一直没去解决这个问题,觉得没什么影响就算了. 今天谷歌了一下,原来是php5没有启用mcrypt模块.   sudo ph ...

  2. Kendo UI for Angular 2 控件

    Kendo UI for Angular 2 控件 伴随着 Angular 2 的正式 release,Kendo UI for Angular 2 的第一批控件已经发布了,当前是 Beta 版本,免 ...

  3. Python字符编码讲解

    声明:本文参考 Python字符编码详解 在计算机中我们不管用什么语言和程序,最终数据在计算机中的都是字节码(也就是01形式)的形式存在的,如果 计算机直接把字节码显示在屏幕上,很明显一般人看不懂字节 ...

  4. Gridview BottomPagerRow添加自定义控件

    pager.ascx public partial class pager : System.Web.UI.UserControl{ } .aspx protected pager ctl; prot ...

  5. [BZOJ 2724] [Violet 6] 蒲公英 【分块】

    题目链接:BZOJ - 2724 题目分析 这道题和 BZOJ-2821 作诗 那道题几乎是一样的,就是直接分块,每块大小 sqrt(n) ,然后将数字按照数值为第一关键字,位置为第二关键字排序,方便 ...

  6. java 反射 动态代理

    在上一篇文章中介绍Java注解的时候,多次提到了Java的反射API.与javax.lang.model不同的是,通过反射API可以获取程序在运行时刻的内部结构.反射API中提供的动态代理也是非常强大 ...

  7. JSP页面的异常处理<转>

     对于jsp页面错误处理这里大致有两种方式:一.在Web.xml中配置全局的错误异常处理    即凡是该项目下(即虚拟路径下的所有文件)的任意一个文件错误或者异常,都会跳到指定的错误处理页面.    ...

  8. STM32F10x 学习笔记6(USART实现串口通讯 2)

    这次讲讲利用串口收发中断来进行串口通讯.STM32 上为每个串口分配了一个中断.也就是说无论是发送完成还是收到数据或是数据溢出都产生同一个中断.程序需在中断处理函数中读取状态寄存器(USART_SR) ...

  9. 关于Mysql当中"Got error 134 from storage engine"的解决办法

    今天在开发程序的时候,有一个表, 当调用这个类别时总是调用不出来,很是恼火.后台打印sql语句为: SELECT * FROM `xx_article` WHERE `cid1` =6 LIMIT 0 ...

  10. Struts2再爆远程代码执行漏洞

    Struts又爆远程代码执行漏洞!在这次的漏洞中,攻击者可以通过操纵参数远程执行恶意代码.Struts 2.3.15.1之前的版本,参数action的值redirect以及redirectAction ...