Hdu5105Math Problem (classification discussion)

Source: Internet
Author: User

Hdu5105Math Problem (classification discussion)

Question link:

Huangjing

Question:

Ideas:

The equation is given. First, the highest coefficient is discussed.
1: If a = 0 & B = 0, then the function is linear and you can directly compare the endpoint.

2 a = 0 & B! If the value is 0, the function is a quadratic function. Calculate the feature value directly, and then compare the endpoint value ..

3! = 0 and there are several cases, then when the feature root B * B-4 * a * c <0 indicates that the function is monotonous, directly compare the endpoint value ..

When the value is greater than 0, you can directly find two roots and then compare them with the endpoint value.

Ps: All feature roots are valid, that is, they must be between [L, R ..



Question:

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 DescriptionHere has an function:
F (x) = |? X3 + B? X2 + c? X + d | (L ≤ x ≤ R)
Please figure out the maximum result of f (x ).
InputMultiple 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)
OutputFor 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

SourceBestCoder Round #18
Recommendheyang | We have carefully selected several similar problems for you: 5106 5103 5102 5101
Statistic | Submit | Discuss | Note
Code:

#include
 
  #include
  
   #include
   
    #include#include
    #include
     
      #include
      
       #include
       
        #include
        
         #define eps 1e-9#define ll long long#define INF 0x3f3f3f3fusing namespace std;priority_queue
         
          ,greater
          
            >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;}
          
         
        
       
      
     
   
  
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.