标签:des style blog http io color ar os sp
题目链接:
题目:
思路:
给出的是一个方程,首先讨论最高项系数。
1:a==0&& b==0 那么函数就是线性的,直接比较端点即可。
2 a==0&&b!=0 那么函数就是二次函数,直接算出特征值,然后比较端点值即可。。
3 a!=0 又有几种情况,那么当特征根 b*b-4*a*c<0 时 说明愿函数是单调,直接比较端点值即可。。
当大于0的时候,直接求出两个根,然后和端点值比较即可
ps:所有的特征根都要是有效的,即都要在[L,R]之间。。
题目:
1.00 2.00 3.00 4.00 5.00 6.00
310.00
#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; }
标签:des style blog http io color ar os sp
原文地址:http://blog.csdn.net/u014303647/article/details/41223111