hdu5105Math Problem(分类讨论)
题目链接:
题目:
思路:
给出的是一个方程,首先讨论最高项系数。
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
f(x)=|a∗x3+b∗x2+c∗x+d|(L≤x≤R)
Please figure out the maximum result of f(x).
1.00 2.00 3.00 4.00 5.00 6.00
310.00
pid=5103" target="_blank" style="color:rgb(26,92,200); text-decoration:none">5103
pid=5102" target="_blank" style="color:rgb(26,92,200); text-decoration:none">5102
5101pid=5100" target="_blank" style="color:rgb(26,92,200); text-decoration:none">5100
pid=5105" style="color:rgb(26,92,200); text-decoration:none">Statistic problemid=5105" style="color:rgb(26,92,200); text-decoration:none">Discuss
代码:
#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;
}
最新文章
- 文件随机读写专用类——RandomAccessFile
- Android 带清除功能的输入框控件EditText
- C# ToolStripProgressBar
- 【Stage3D学习笔记续】山寨Starling(六):动画实现和测试
- JAVA工程师面试总结
- 一直想测试的NGINX变量输出,最于有办法了。
- xamarin android alertdialog详解
- SpringBoot入门(0) HelloWorld的实现与原理分析
- 51Nod-1436 方程的解数
- 第二弹:超全Python学习资源整理(进阶系列)
- centos7 keepalived+nginx实现vip漂移高可用
- apt-get update 与 apt-get upgrade 的区别
- wk1&;2 字符串
- ubuntu下配置时间同步NTP
- setBit testBit权限管理
- Linux 下crontab 详解转
- 【ARC068F】Solitaire
- 三:Bootstrap-js插件
- XML与web开发-01- 在页面显示和 XML DOM 解析
- [翻译] JHChainableAnimations
热门文章
- python 添加自定义库
- HashMap导致死循环问题
- MRv2 工作机制 、 公平调度器、MR压缩、边数据
- 保留全部Android crash信息
- cocos2d-x-3.3rc2-003 cocos中的引用计数和自己主动释放池
- HDU5411CRB and Puzzle(矩阵高速幂)
- Found conflicts between different versions of the same dependent assembly that could not be resolved
- JAVA设计模式之【外观模式】
- C#调用Exe程序示例
- Android ViewPager系列之ViewPager一屏显示多个子页面