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

我注意讨论了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. CoreThink主题开发(九)使用H-ui开发博客主题之用户个人主页

    感谢H-ui.感谢CoreThink!  效果图: 这里使用table布局 /Theme/Blog/User/Index/home.html <extend name="$_home_ ...

  2. django事物回滚

    往数据库写入数据时,不经意间就会写入不完整的数据,我们称之为脏数据.事务管理(transaction)可以防止这种情况发生.事务管理一旦检测到写入异常,会执行回滚操作,即要么写入完整的数据,要么不写入 ...

  3. NSOperation简介

    1.NSOperation的作用 配合使用NSOperation和NSOperationQueue也能实现多线程编程. 2.NSOperation和NSOperationQueue实现多线程的具体步骤 ...

  4. python常用模块-1

    一.认识模块 1.什么是模块:一个模块就是一个包含了python定义和声明的文件,文件名就是加上.py的后缀,但其实import加载的模块分为四个通用类别 : 1.使用python编写的代码(.py文 ...

  5. mysql只能连接localhost解决

    grant all privileges on *.* to 'root'@'%' identified by 'root';flush privileges;

  6. Jquery.ScrollLoading图片延迟加载技术

    关于分屏加载图片,像天猫.京东等电商图片较多页面很长,就采用了延迟加载技术. 目前很流行的做法就是滚动动态加载,显示屏幕之外的图片默认是不加载的, 随着页面的滚动,显示区域图片才被动态加载. 原理其实 ...

  7. Understanding When to use RabbitMQ or Apache Kafka

    https://content.pivotal.io/rabbitmq/understanding-when-to-use-rabbitmq-or-apache-kafka How do humans ...

  8. Python学习进程(2)Python环境的搭建

        本节主要介绍在windows和Linux平台上如何搭建Python编程环境.     (1)查看Python版本: windows: C:\Users\JMSun>python 'pyt ...

  9. Dubbo框架入门介绍

    背景 随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,亟需一个治理系统确保架构有条不紊的演进. 单一应用架构 当网站流量很小时,只需一个 ...

  10. Linux权限管理 文件特殊权限

    概述 除了我们前面介绍的rwx权限外,Linux中还有另外三种特殊权限:SUID,SGID,SBIT   权限    执行条件 执行示例 SUID s出现在文件所有者的x权限上. 1. SUID只能用 ...