Strange fuction hdu 2899

Strange fuction

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4803    Accepted Submission(s): 3428

Problem Description
Now, here is a fuction:
  F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (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 line has only one real numbers Y.(0 < Y <1e10)
 
Output
Just the minimum value (accurate up to 4 decimal places),when x is between 0 and 100.
 
Sample Input
2 100 200
 
Sample Output
-74.4291 -178.8534
 
Author
Redow
题意:给一式子,还有变量范,0-100,让求最小值,。导数等于0时,二分查找导数等于0的时候的x~我怎么把二分这么重要的查找方式给忘了呢,当时还在想这x是实数怎么找啊~蠢到猪
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 
 5 using namespace std;
 6 
 7 double y;
 8 
 9 double slove(double x)
10 {
11     return 42.0*x*x*x*x*x*x+48.0*x*x*x*x*x+21.0*x*x+10.0*x-y;
12 }
13 double get(double x)
14 {
15     return 6.0*x*x*x*x*x*x*x+8.0*x*x*x*x*x*x+7.0*x*x*x+5.0*x*x-y*x;
16 }
17 
18 int main()
19 {
20     int t;
21     scanf("%d", &t);
22     while(t--)
23     {
24         scanf("%lf", &y);
25         double l = 0.0, r = 100.0;
26         while(r-l >= 1e-6)  //  double 比较,不能写成 r > l 
27         {
28             double mid = (l+r)/2;
29             if(slove(mid) > 0)
30                 r = mid;
31             else
32                 l = mid;
33         }
34         printf("%.4f
", get(l));
35     }
36     return 0;
37 }

蠢成猪肿么办~

让未来到来 让过去过去
原文地址:https://www.cnblogs.com/Tinamei/p/4749724.html