题意略。
思路:
考察导数和分类讨论的思想,因为在做题时少讨论一种情况,所以wa了。
#include<bits/stdc++.h> using namespace std; double a,b,c,d,L,R; double func(double x){ return fabs(a * x * x * x + b * x * x + c * x + d); } int main(){ while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&L,&R) == 6){ double ans = 0; double ansl = func(L),ansr = func(R); if(a != 0){ double d = b * b - 3 * a * c; if(d <= 0){ ans = max(ansl,ansr); } else{ double x1 = (-1 * b - sqrt(d)) / (3 * a); double x2 = (-1 * b + sqrt(d)) / (3 * a); double ans1 = func(x1),ans2 = func(x2); if(L <= x1 && x2 <= R){ ans = max(max(ans1,ans2),max(ansl,ansr)); }else if(R <= x1 || L >= x2){ ans = max(ansl,ansr); }else if(L <= x1 && x1 <= R && R <= x2){ ans = max(ans1,max(ansl,ansr)); }else if(x1 <= L && R <= x2){ ans = max(ansl,ansr); }else if(x1 <= L && L <= x2 && x2 <= R){ ans = max(ans2,max(ansl,ansr)); } } }else if(b != 0){ double x0 = -c / (2 * b); if(R <= x0){ ans = max(ansl,ansr); }else if(L <= x0 && x0 <= R){ ans = max(func(x0),max(ansl,ansr)); }else{ ans = max(ansl,ansr); } }else if(c != 0){ ans = max(ansl,ansr); }else{ ans = fabs(d); } printf("%.2lf ",ans); } return 0; }