hdu 2199 Can you solve this equation? 二分

Can you solve this equation?

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


Problem Description
Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,can you find its solution between 0 and 100;
Now please try your lucky.
 

 

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 a real number Y (fabs(Y) <= 1e10);
 

 

Output
For each test case, you should just output one real number(accurate up to 4 decimal places),which is the solution of the equation,or “No solution!”,if there is no solution for the equation between 0 and 100.
 

 

Sample Input
2
100 -4
 

 

Sample Output
1.6152
No solution!
 

 

Author
Redow
 

 

Recommend
lcy   |   We have carefully selected several similar problems for you:   2899  2289  2298  2141  3400 
 
 
 1 /*

 2 对于精度,我表示囧。

 3 我以为,保留4位小数,就到1e-5就可以了。

 4 

 5 */

 6 

 7 #include<iostream>

 8 #include<stdio.h>

 9 #include<cstring>

10 #include<cstdlib>

11 #include<math.h>

12 using namespace std;

13 

14 double fun(double x)

15 {

16     return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6;

17 }

18 void EF(double l,double r,double Y)

19 {

20     double mid;

21     while(r-l>1e-7)

22     {

23         mid=(l+r)/2;

24         double ans=fun(mid);

25         if( ans >Y )

26             r=mid-1e-8;

27         else l=mid+1e-8;

28     }

29     printf("%.4lf\n",(l+r)/2);

30 }

31 int main()

32 {

33     int T;

34     double Y;

35     scanf("%d",&T);

36     {

37         while(T--)

38         {

39             scanf("%lf",&Y);

40             if( fun(0.0)>Y || fun(100.0)<Y)

41                 printf("No solution!\n");

42             else

43                  EF(0.0,100.0,Y);

44         }

45     }

46     return 0;

47 }

 

你可能感兴趣的:(this)