【HDU】5105 Math Problem
来源:互联网 发布:seo招聘北京 编辑:程序博客网 时间:2024/04/30 21:41
传送门:【HDU】5105 Math Problem
题目分析:如果a不等于0,说明是一元三次方程,求个导取极值的坐标以及两端点的坐标,带入f(x)求个最大值就好。如果a等于0,那么如果b不等于0,则是一元二次方程,直接得到极值坐标,和两端点的坐标带入f(x)中求个最大值。如果b也等于0,那么ans = max (f(L),f(R))。
注意极值坐标是否存在以及是否可行。
代码如下:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cmath>using namespace std ;typedef long long LL ;#pragma comment ( linker , "/STACK:1024000000" )#define rep( i , a , b ) for ( int i = ( a ) ; i < ( b ) ; ++ i )#define For( i , a , b ) for ( int i = ( a ) ; i <= ( b ) ; ++ i )#define rev( i , a , b ) for ( int i = ( a ) ; i >= ( b ) ; -- i )#define rec( i , A , o ) for ( int i = A[o] ; i != o ; i = A[i] )#define clr( a , x ) memset ( a , x , sizeof a )double a , b , c , d , L , R ;double f ( double x ) {return fabs ( a * x * x * x + b * x * x + c * x + d ) ;}void solve () {double x1 , x2 ;double ans = max ( f ( L ) , f ( R ) ) ;if ( a ) {double sqr = 4 * b * b - 12 * a * c ;if ( sqr < 0 ) x1 = x2 = 10000 ;else {x1 = ( - 2 * b - sqrt ( sqr ) ) / ( 6 * a ) ;x2 = ( - 2 * b + sqrt ( sqr ) ) / ( 6 * a ) ;}if ( L <= x1 && x1 <= R ) ans = max ( ans , f ( x1 ) ) ;if ( L <= x2 && x2 <= R ) ans = max ( ans , f ( x2 ) ) ;} else if ( b ) {double x = - c / 2 / b ;if ( L <= x && x <= R ) ans = max ( ans , f ( x ) ) ;}printf ( "%.2f\n" , ans ) ;}int main () {while ( ~scanf ( "%lf%lf%lf%lf%lf%lf" , &a , &b , &c , &d , &L , &R ) ) solve () ;return 0 ;}
0 0
- 【HDU】5105 Math Problem
- HDU - 5105 Math Problem
- HDU-5105 Math Problem
- HDU 5105 Math Problem
- HDU 5105 Math Problem
- HDU 5105 Math Problem
- hdu 5105 Math Problem(数学)
- hdu 5105——Math Problem
- HDU 5105 Math Problem --数学,求导
- HDU 5105 Math Problem(数学)
- hdu 5105 Math Problem(数学)
- Math Problem HDU
- A Math Problem HDU
- hdu A Simple Math Problem
- A Simple Math Problem (HDU
- HDU 6182 A Math Problem
- A Simple Math Problem HDU
- A Simple Math Problem HDU
- 在dos命令行里面INSERT中文总是报错解决办法
- 我的大学,追忆高三(永不能忘的332)
- unity3d学习之预设体
- 【软件工程】软件开发的领路者——过程模型
- 多线程中的使用共享变量的问题
- 【HDU】5105 Math Problem
- 斐波那契数列
- 细数AutoLayout以来UIView和UIViewController新增的相关API
- Axture+SVN--团队中如何管理原型图
- java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFil
- 【第三章·栈和队列】思维导图
- struts的工作流程
- Unity3d学习之音频
- Win8常用快捷键