hdu 2199

 1 //二分查找
 2 #include<stdio.h>
 3 #include<math.h>
 4 #define eps 1e-7
 5 double fun(double x)
 6 {
 7     return 8*pow(x,4)+7*pow(x,3)+2*pow(x,2)+3*x+6;
 8 }
 9 double bin_search(double Y)
10 {
11     double low=0.0,high=100.0,mid;
12     while(high-low>eps)
13     {
14         mid=(low+high)/2.0;
15         if(fun(mid)<Y)
16             low=mid+eps;
17         else
18             high=mid-eps;
19     }
20     return (low+high)/2;
21 }
22 int main()
23 {
24     int t;
25     double Y,ans;
26     scanf("%d",&t);
27     while(t--)
28     {
29         scanf("%lf",&Y);
30         if(fun(0)<=Y&&Y<=fun(100))
31         {    
32             ans=bin_search(Y);
33             printf("%.4lf\n",ans);
34         }
35         else
36             printf("No solution!\n");
37     }
38     return 0;
39 }

 

posted @ 2012-08-09 16:55  M_cag  阅读(270)  评论(0编辑  收藏  举报