hdu5105Math Problem(分类讨论)
来源:互联网 发布:squid默认端口 编辑:程序博客网 时间:2024/06/06 09:21
题目链接:
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).
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
BestCoder Round #18
Recommend
heyang | We have carefully selected several similar problems for you: 5106 5103 5102 5101 5100
代码:
#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 0x3f3f3f3fusing 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;}
0 0
- hdu5105Math Problem(分类讨论)
- 【HDU】5296 Annoying problem【树链剖分+分类讨论】
- Codeforces Problem 709B Checkpoints(分类讨论)
- Codeforces Problem 702D Road to Post Office(分类讨论)
- Codeforces Problem 714B Filya and Homework(分类讨论)
- 分类讨论
- UOJ295,大力分类讨论
- FZU Problem 2213 Common Tangents(简单几何,分类讨论)——第六届福建省大学生程序设计竞赛-重现赛
- [讨论]ZOJ Problem Set - 1201
- BZOJ 2503 相框 分类讨论
- Codeforces R278 div2B 分类讨论
- Finals in arithmetic 分类讨论
- codeforces 789B(分类讨论)
- bzoj1177 [Apio2009] Oil 分类讨论
- NLP 分类问题的讨论
- Josephus Problem 约瑟夫环问题的讨论
- HDU 1061 Rightmost Digit(分类讨论)
- GCJ 2015R1B(Noisy Neighbors-分类讨论)
- C#开源图表组件
- nginx 新手攻略 Ubuntu Linux下安装配置教程
- 杭电ACM-The area
- Ubuntu14.04下搭建Boa web服务器
- 创建简单多边形窗口--并旋转起来
- hdu5105Math Problem(分类讨论)
- 求三角形
- 利用Perl中的Cisco模块登录公司交换机
- <二>Oracle多表主键外键+inner join/left join/right join
- Eclipse增加Maven Archetype Catalogs
- 安卓自学笔记:13:选项菜单和子菜单
- Apache Twill—YARN上应用程序开发包
- 用Python开始机器学习(2:决策树分类算法)
- Http访问网络之GET和POST