hdu 2899 Strange fuction (二分)

题目链接:http://acm.hdu.edu.cn/showproblem.pihp?pid=2899

题目大意:找出满足F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)的x值。注意精确度的问题。

     求满足条件的x的最小值!!求导,利用单调性来找到最小值。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 using namespace std;
 5 double y;
 6 
 7 double derivation(double x)
 8 {
 9     return 42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*x;
10 }
11 
12 double result(double x)
13 {
14     return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x;
15 }
16 
17 int main ()
18 {
19     int t;
20     cin>>t;
21     while (t--)
22     {
23         double x;
24         cin>>y;
25         double l=0,r=100;
26         while (r-l>1e-8)
27         {
28             x=(r+l)/2;
29             double yy=derivation(x);
30             if (y>yy)
31             l=x+1e-8;
32             else
33             r=x-1e-8;
34         }
35         x=(l+r)/2;
36         printf ("%.4lf
",result(x));
37     }
38     return 0;
39 }
原文地址:https://www.cnblogs.com/qq-star/p/3888221.html