Can You solve this equation?
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 20612 Accepted Submission (s): 9045
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 10 0;
Now 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);
Should just output one real number (accurate up to 4 decimal places), which is the solution O f 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!
It's a simple question. WA several times ... The first is that the input x may be floating point, followed by the function is monotonically incrementing and has a range of values, exceeding the maximum value of the output has no results, and finally the accuracy of the calculation, although the retention of 4 bits but still to calculate to 1e-8 or less ...
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int main ()
{
int T;
Double x,y,z,l,h;
cin>>t;
while (t--) {
cin>>y;
if (y<6| | y>807020306) {
cout<< "No solution!" <<endl;
Continue;
}
x=50.0;
h=100.0;
l=0.0;
while (Fabs (h-l) >1e-8) {
z=8.0*x*x*x*x + 7.0*x*x*x + 2.0*x*x + 3.0*x + 6.0;
if (z>y) {
h=x;
} else{
l=x;
}
x= (h+l)/2;
}
printf ("%.5lf\n", x);
printf ("%.4lf\n", x);
}
return 0;
}