Can you solve this equation? |
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
Total Submission(s): 164 Accepted Submission(s): 94 |
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! 这道题用的是二分搜索法 二分法原理 给定方程f(x)=0,设f(x)在区间[a,b]连续,且f(a)f(b)<0,则方程f(x)在(a,b)内 至少有一根,为便于讨论,不妨设方程f(x)=0在(a,b)内只有一实根 采取使有根区间逐步缩小,从而得到满足精度要求的实根 的近似值。 取[a,b]区间二等分的中点x0 =(a+b)/2, 若f(x0)=0,则x0是f(x)=0的实根 若f(a)f(b)<0 成立, 则必在区间(a, x0)内,取a1=a,b1= x0; 否则必在区间(x0,b)内,取a1= x0,b1=b, 这样,得到新区间(a1,b1),其长度为[a,b]的一半, 如此继续下去,进行k次等分后,得到一组不断缩小的区间, [a,b],[a1,b1],......[ak,bk].
分析本题得:函数是一个单调递增的函数;所以此函数的0点只有一个。本题的精度为0.0001,保证小数点后前四位相同。 1 #include <iostream> |