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.
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!
题意:输入y的值,则求出方程8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y的解,若有解,则该解一定在[0, 100]之间,输出x,若无解则输出No solution!。
#include<stdio.h> #include<math.h> int main () { double a, b, c, y, sum, d; int T, x; scanf("%d", &T); while (T--) { scanf("%lf", &y); x = 0; a = 0; b = 100; d = 8*b*b*b*b + 7*b*b*b + 2*b*b + 3*b + 6; c = 8*a*a*a*a + 7*a*a*a + 2*a*a + 3*a + 6; if (y >= c && y <= d) x = 1; if (x) { while (b-a > 1e-6) ///浮点数判断b是否大于a { c = (a+b)/2; sum = 8*c*c*c*c + 7*c*c*c + 2*c*c + 3*c + 6; if (sum > y) b = c-1e-7; else a = c+1e-7; } printf("%.4lf ", (a+b)/2); } if (x == 0) printf("No solution! "); } return 0; }