ACM Course Practice 2--1002

Source: Internet
Author: User

Title Description

Now, this is a fuction:
F (x) = 6 * x^7+8x^6+7x^3+5x^2-yx (0 <= x <=100)
Can you find the minimum value when x is between 0 and 100.

Input
The first line of the input contains an integer T (1<=t<=100) which means the number of test cases. Then T-lines follow, each of the line have only one real numbers y. (0 < y <1e10)

Output
Just the minimum value (accurate up to 4 decimal places) while X is between 0 and 100.

Sample Input

2
100
200

Sample Output

-74.4291
-178.8534
Effect

To find the minimum value of the function in the interval [0,100]

Ideas

Derivative of the function f ' (x) =42* x^6+48x^5+21x^2+10x-y
, and then derivative of the derivative function, it is found that the derivative function is monotonically increasing.
It is concluded that the minimum value of the function is
the root of x^6+48x^5+21x^2+10*x=y.
The program should first determine whether the root is within the [0,100] interval, divided into three kinds of situations discussed.
The code of this problem is not very different from the first question, it is the first problem of deformation

AC Code
  
 
  1. #include<iostream>
  2. #include<iomanip>
  3. #include<stdio.h>
  4. #include<cmath>
  5. using namespace std;
  6. double f_d(double res)
  7. {
  8. returnRes*Res*Res*Res*Res*Res* the +Res*Res*Res*Res*Res* - +Res*Res* + +Res* Ten;
  9. }
  10. double f(double res,double y){
  11. returnRes*Res*Res*Res*Res*Res*Res*6 +Res*Res*Res*Res*Res*Res*8 +Res*Res*Res*7 +Res*Res* 5-Res*y;
  12. }
  13. int main(){
  14. //freopen("date.in", "r", stdin);
  15. //freopen("date.out", "w", stdout);
  16. int T;
  17. double a;
  18. double b,e,tem;
  19. cin>>T;
  20. for(int i=0;i<T;i++){
  21. cin>>a;
  22. if(f_d(100)<=a)
  23. cout<<fixed<<setprecision(4)<<f(100,a)<<endl;
  24. else
  25. if(f_d(0)>=a)
  26. cout<<fixed<<setprecision(4)<<f(0,a)<<endl;
  27. else{
  28. b = 0 , e = 100 tem Span class= "pun" >= 50 ;
  29. while (fabs(f_d(tem) - a) >= 1e-7)
  30. if (f_d(tem)>a){
  31. e = tem;
  32. tem = (b + e) / 2;
  33. }
  34. else{
  35. b = tem;
  36. tem = (b + e) / 2;
  37. }
  38. cout<<fixed<<setprecision(4)<<f(tem,a)<<endl;
  39. }
  40. }
  41. }


From for notes (Wiz)

ACM Course Practice 2--1002

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.