题目链接:

huangjing

题目:

思路:

给出的是一个方程,首先讨论最高项系数。

1:a==0&& b==0  那么函数就是线性的。直接比較端点就可以。

2   a==0&&b!=0  那么函数就是二次函数。直接算出特征值,然后比較端点值就可以。。

3  a!=0  又有几种情况,那么当特征根  b*b-4*a*c<0 时  说明愿函数是单调,直接比較端点值就可以。

当大于0的时候,直接求出两个根,然后和端点值比較就可以

ps:全部的特征根都要是有效的,即都要在[L,R]之间。

题目:

Math Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 943    Accepted Submission(s): 250

Problem Description
Here has an function:

  f(x)=|a∗x3+b∗x2+c∗x+d|(L≤x≤R)

Please figure out the maximum result of f(x).
 
Input
Multiple test cases(less than 100). For each test case, there will be only 1 line contains 6 numbers a, b, c, d, L and R. (−10≤a,b,c,d≤10,−100≤L≤R≤100)
 
Output
For each test case, print the answer that was rounded to 2 digits after decimal point in 1 line.
 
Sample Input
1.00 2.00 3.00 4.00 5.00 6.00
 
Sample Output
310.00
 
Source
 
Recommend
 

pid=5105" style="color:rgb(26,92,200); text-decoration:none">Statistic | Submit | 

problemid=5105" style="color:rgb(26,92,200); text-decoration:none">Discuss | Note


代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#define eps 1e-9
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
priority_queue<int,vector<int>,greater<int> >Q; double a,b,c,d,l,r; double f(double x)
{
return fabs(a*x*x*x+b*x*x+c*x+d);
} int main()
{
double ans;
while(~scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&l,&r))
{
if(a==0&&b!=0)
{
double x=-c/(2*b);
ans=max(f(l),f(r));
if(x>=l&&x<=r)
ans=max(ans,f(x));
}
else if(a==0&&b==0)
ans=max(f(l),f(r));
else if(a!=0)
{
double xx=4*b*b-12*a*c;
if(xx<0)
ans=max(f(l),f(r));
else
{
double x1=(-2*b+sqrt(xx))/(6*a);
double x2=(-2*b-sqrt(xx))/(6*a);
ans=max(f(l),f(r));
if(x1>=l&&x1<=r)
ans=max(ans,f(x1));
if(x2>=l&&x2<=r)
ans=max(ans,f(x2));
}
}
printf("%.2lf\n",ans);
}
return 0;
}

hdu5105Math Problem(分类讨论)的更多相关文章

  1. D. Easy Problem dp(有衔接关系的dp(类似于分类讨论) )

    D. Easy Problem dp(有衔接关系的dp(类似于分类讨论) ) 题意 给出一个串 给出删除每一个字符的代价问使得串里面没有hard的子序列需要付出的最小代价(子序列不连续也行) 思路 要 ...

  2. Codeforces 1513F - Swapping Problem(分类讨论+乱搞)

    Codeforces 题目传送门 & 洛谷题目传送门 简单题,难度 *2500 的 D2F,就当调节一下一模炸裂了的自闭的心情,稍微写写吧. 首先我看到这题的第一反应是分类讨论+数据结构,即枚 ...

  3. cf 251 B Playing with Permutations 暴力 分类讨论

    题链;http://codeforces.com/problemset/problem/251/B B. Playing with Permutations time limit per test 2 ...

  4. CCCC L2-010. 排座位【并查集/分类讨论】

    L2-010. 排座位 时间限制 150 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 布置宴席最微妙的事情,就是给前来参宴的各位宾客安排座位. ...

  5. HDU 6627 equation (分类讨论)

    2019 杭电多校 5 1004 题目链接:HDU 6627 比赛链接:2019 Multi-University Training Contest 5 Problem Description You ...

  6. HDU 6665 Calabash and Landlord (分类讨论)

    2019 杭电多校 8 1009 题目链接:HDU 6665 比赛链接:2019 Multi-University Training Contest 8 Problem Description Cal ...

  7. Codeforces 460D Little Victor and Set --分类讨论+构造

    题意:从区间[L,R]中选取不多于k个数,使这些数异或和尽量小,输出最小异或和以及选取的那些数. 解法:分类讨论. 设选取k个数. 1. k=4的时候如果区间长度>=4且L是偶数,那么可以构造四 ...

  8. BZOJ-1067 降雨量 线段树+分类讨论

    这道B题,刚的不行,各种碎点及其容易忽略,受不鸟了直接 1067: [SCOI2007]降雨量 Time Limit: 1 Sec Memory Limit: 162 MB Submit: 2859 ...

  9. UVaLive 6862 Triples (数学+分类讨论)

    题意:给定一个n和m,问你x^j + y^j = z^j 的数量有多少个,其中0 <= x <= y <= z <= m, j = 2, 3, 4, ... n. 析:是一个数 ...

随机推荐

  1. js应用中的小细节-时间戳的转换和input输入框有效数字

    1 input输入框内value值保留有效数字,js自带的方法.toFixed(),但是直接使用会报错,因为不论输入框内输入汉字.字母还是数字,类型都是string.解决的办法是将其转换为number ...

  2. java有参无参构造器的的执行顺序

    这里拿了用数组构造栈的一段代码说明一下 public class StackArray<E> { private Object[] data = null; private int max ...

  3. ASP.NET-dropdownlist默认值

    可以在第三个选项中定义一个默认值,但是返回数据的时候就不需要这种类似"请选择名称"之类的提示了,所以在构造seleclt option的时候,要在option中的属性中加上sele ...

  4. spring boot和maven的约定大于配置体现在哪些方面

    spring boot和maven的约定大于配置体现在哪些方面? 两者都遵从了约定大于配置的路线 约定优于配置体现点: 1.maven的目录文件结构 1)默认有resources文件夹,存放资源配置文 ...

  5. [ReactVR] Render Custom 3D Objects Using the Model Component in React VR

    React VR isn't limited to simple 3D primitives. By using the <Model/> Component we can place a ...

  6. Navgationcontroller 的pop

    1.NavgationController pop 回来不进入viewdisload,利用原来载入的视图 不是啊,他pop回来的时候不进viewdidload 直接进去viewwillApper这种方 ...

  7. 5种语言混合编程:C++、JS、python、Lisp、汇编

    /* 混合C++.JS.python.Lisp.汇编 1种语言,5种语法 */ main { //C++ vector<int> v; v.push(2); putsl(v.size()) ...

  8. 使用Ant打包Android应用具体解释

    计划写个完整的使用Ant打包Android应用的系列文章.三篇文章.首篇具体介绍採用Ant打包Android应用的流程.列出部分定制问题及其解决方法,第二篇介绍我理解的Ant打包的思路与主要的概念和使 ...

  9. m_Orchestrate learning system---二、如何实现验证码自动点击刷新

    m_Orchestrate learning system---二.如何实现验证码自动点击刷新 一.总结 一句话总结:传过去的url带随机数来避免读取缓存 onclick="this.src ...

  10. 在CentOS下安装tomcat并配置环境变量(改默认端口8080为8081)

    不多说,直接上干货! 第一步:下载tomcat压缩包 http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.73/bin/ 第二步:上传tomcat压 ...