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

我注意讨论了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. KGX滚动分页源码

    源码描述: 本工具采用Jquery框架,通过jquery调用ashx获取并输出数据,示例中采用测试数据,可以自行扩展为图片等等 当下流行的分页方式,鼠标滚动下拉条会自动展示下一页信息,类似瀑布流的效果 ...

  2. iframe与父窗口之间数据互相获取

    Js/Jquery获取iframe中的元素 博客分类: jquery javascript jquery  在web开发中,经常会用到iframe,难免会碰到需要在父窗口中使用iframe中的元素.或 ...

  3. linux systemctl 指令 —— 阮一峰

    Systemd 指令 原文链接如果有效,请点击原文链接查看.原文:http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.ht ...

  4. 【leetcode刷题笔记】Multiply Strings

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  5. Ajax跨域请求action方法,无法传递及接收cookie信息(应用于系统登录认证及退出)解决方案

    最近的项目中涉及到了应用ajax请求后台系统登录,身份认证失败,经过不断的调试终于找到解决方案. 应用场景: 项目测试环境:前端应用HTML,js,jQuery ajax请求,部署在Apache服务器 ...

  6. Listening Carefully SP1403S

    Listening Carefully仔细聆听When people talk, listen completely. Most people never listen. ―Ernest Heming ...

  7. 简要总结ajax工作原理及优缺点

    虽然在实际的项目中使用多种ajax请求,但就其工作原理,优缺点尚未深入总结, 参考:http://www.cnblogs.com/SanMaoSpace/archive/2013/06/15/3137 ...

  8. class_exists — 检查类是否已定义

    class_exists — 检查类是否已定义 bool class_exists ( string $class_name [, bool $autoload = true ] ) 检查指定的类是否 ...

  9. flume 使用遇到问题及解决

    1. ../flume/fchannel/spool/data/ 目录下发生缓存文件积压 可能原因:同一时间同一客户端下向两个监控目录mv文件:或同一时间多个客户端向服务端上传文件 2.清空../fl ...

  10. whois老域名挖掘技术

    我一般通过站长工具域名WHOIS查询定向收集一些特定域名,拿来分析网站存活站点. 例如: 查询域名基本信息 WHOIS反查得到大部分域名注册信息 一般大一点的厂商都有几百个域名,我们通过此处收集大量顶 ...