最大值无非就是在两个端点或极值点处取得。

我注意讨论了a=0和b=0,却忽略了极值点可能不在L到R的范围内这一问题。被Hack了。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<sstream>
using namespace std;
#define pii pair<int,int>
#define LL long long int
const int eps=1e-;
const int INF=;
const int maxn=+;
double a,b,c,d,L,R,ans;
double f(double x)
{
return fabs(a*x*x*x+b*x*x+c*x+d);
}
int main()
{
//freopen("in10.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&L,&R)==)
{
if(a!=)
{
if(a<)
{
a=-a;
b=-b;
c=-c;
d=-d;
}
double pan=b*b-*a*c;
if(pan<=)
{
printf("%.2f\n",max(f(L),f(R)));
}
else
{
double x1=(-sqrt(pan)-b)/(*a);
double x2=(sqrt(pan)-b)/(*a);
if(x1>=L&&x1<=R&&x2>=L&&x2<=R)
printf("%.2f\n",max(max(f(L),f(R)),max(f(x1),f(x2))));
else if(x1>=L&&x1<=R)
printf("%.2f\n",max(f(L),max(f(R),f(x1))));
else if(x2>=L&&x2<=R)
printf("%.2f\n",max(f(L),max(f(R),f(x2))));
else printf("%.2f\n",max(f(L),f(R)));
}
}
else
{
if(b==) printf("%.2f\n",max(f(L),f(R)));
else
{
double z=(-c)/(*b);
if(z<=R&&z>=L)
printf("%.2f\n",max(f(L),max(f(R),f(z))));
else printf("%.2f\n",max(f(L),f(R)));
}
}
}
//fclose(stdin);
//fclose(stdout);
return ;
}

BestCoder Round #18(hdu5105)Math Problem(高中数学)的更多相关文章

  1. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) A. Math Problem 水题

    A. Math Problem Your math teacher gave you the following problem: There are n segments on the x-axis ...

  2. 2016ICPC-大连 A Simple Math Problem (数学)

    Given two positive integers a and b,find suitable X and Y to meet the conditions: X+Y=a Least Common ...

  3. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) A Math Problem

    //只要从所有区间右端点的最小值覆盖到所有区间左端点的最大值即可 #include<iostream> using namespace std ; int x,y; int n; int ...

  4. Math Problem(数学)

    链接:https://ac.nowcoder.com/acm/contest/893/C来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K ...

  5. BestCoder Round #29——A--GTY's math problem(快速幂(对数法))、B--GTY's birthday gift(矩阵快速幂)

    GTY's math problem Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

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

  7. hdu 5105 Math Problem(数学)

    pid=5105" target="_blank" style="">题目链接:hdu 5105 Math Problem 题目大意:给定a.b ...

  8. hdu 5667 BestCoder Round #80 矩阵快速幂

    Sequence  Accepts: 59  Submissions: 650  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536 ...

  9. hdu----(5055)Bob and math problem(贪心)

    Bob and math problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

随机推荐

  1. 使用TortoiseGit查看以前Commit的各个快照(snapshot)

    Swith/Checkout提供了这个功能. 比如从bcbc66627334204f879eff99f68e70af0ca7907e回退到dc3f82f2532fcb95e4f24c9f9c331a7 ...

  2. MySQL数据库(8)_MySQL数据库总结

    sql语句规范 sql是Structured Query Language(结构化查询语言)的缩写.SQL是专为数据库而建立的操作命令集,是一种功能齐全的数据库语言. 在使用它时,只需要发出“做什么” ...

  3. MongoDB环境配置

    在官网上下载MongoDB可执行文件安装在电脑上后,想要运行需先安装路径下新建一个data文件夹,再在里面新建db文件夹用户存放数据库文件和相关配置. 在bin目录里面运行命令行: 这样MongoDB ...

  4. 嵌入式C函数优化

    0. 引言 这是一个简单函数的优化,但却体现了代码易读性和效率的综合考虑. 如果问我如何写出优秀的代码,答曰:再写一版. 1. 版本1 从环形buffer中取出数据,然后放到一个结构体中.buffer ...

  5. 字符串哈希小结(BKDR,RK)

    前言 A:这么简单的东西,怎么现在才学?? B:别提了,还不是因为菜o(╥﹏╥)o A:那打算讲些什么东西 B:\(BKDRHash\).\(Rabin-karp\)以及简单应用 简洁 所谓字符串哈希 ...

  6. IDEA使用前的各种基本设置(转)

    先搞个链接,以后自己慢慢总结:传送门

  7. MIPI DBI\DPI\DSI简介【转】

    本文转载自:http://blog.csdn.net/longxiaowu/article/details/24249971 (1)DBI接口 A,也就是通常所讲的MCU借口,俗称80 system接 ...

  8. 高通平台MSM8916LCM模块移植(一)-bootloader部分【转】

    本文转载自:http://www.mobile-open.com/2016/970947.html 高通平台中的bootloader叫做LK(Little Kernel,对于LCM来说LK部分相当重要 ...

  9. Java final static关键字

    Java中的final关键字 使用 final 关键字做标识有 “最终的” 含义. final 可以修饰 类.方法.属性.变量 final 修饰类: 则该类不允许被继承 final 修饰方法:则该方法 ...

  10. POJ 1459 网络流 EK算法

    题意: 2 1 1 2 (0,1)20 (1,0)10 (0)15 (1)20 2 1 1 2 表示 共有2个节点,生产能量的点1个,消耗能量的点1个, 传递能量的通道2条:(0,1)20 (1,0) ...