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

我注意讨论了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. Eclipse 变量高亮显示设置

    A:Window-> preferences->java->Editor->Mark Occurences Local variables就是变量的高亮显示

  2. Python之简单函数练习(Day30)

    1.写函数,,用户传入修改的文件名,与要修改的内容,执行函数,完成批了修改操作 def modify_file(filename,old,new): import os with open(filen ...

  3. VS 无法调试 IIS

    用附加的方式断点无效时.   解决方案: 一.VS设置的  .Net版本 与 IIS应用程序池的版本  不一致.   操作步骤: 1. 在VS-> 项目属性, 配置 自定义Web服务器 , 这里 ...

  4. VM and Docker Container

    https://www.zhihu.com/question/48174633 在开始讨论前,先抛出一些问题,可先别急着查看答案,讨论的过程可以让答案更有趣,问题如下: Docker 容器有自己的ke ...

  5. Linux sh远程连接失败 sshd.service启动失败

    今天不小心在本机的虚拟机执行了 chmod -R 777 /var 导致/var目录下所有权限全部是777 其中 /var/empty/sshd目录权限必须是744,却被改成了777,致使sh远程连接 ...

  6. GPU的工作原理

    转:https://blog.csdn.net/p23onzq/article/details/79609629 在GPU出现以前,显卡和CPU的关系有点像“主仆”,简单地说这时的显卡就是画笔,根据各 ...

  7. CSS3透明背景表单

    在线演示 本地下载

  8. pearson相关分析在R中的实现

    三个相关性函数: cor():R自带的,输入数据可以是vector,matrix,data.frame,输出两两的相关系数R值 cor.test():R自带的,输入数据只能是两个vector,输出两个 ...

  9. requests.post处理Content-Type: multipart/form-data的请求

    前几天遇到一个需求,要调用一个接口发送请求,抓包之后得到的数据是这样的 上网看了一些资料得知,原来这个接口的数据是通过multipart/form-data格式传过去的,multipart/form- ...

  10. linux虚拟机ping通主机

    右键虚拟机,选择网络适配器,设置为桥接模式.然后关闭主机防火墙,ping就行了(一直ping是没有参数的)