Can You solve this equation?
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 13292 Accepted Submission (s): 5937
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!
Source code (two-point lookup)
#include <stdio.h>
#include <math.h>
double F (double x)
{
return 8*pow (x,4) + 7*pow (x,3) +2*pow (x,2) +3*x+6;
}
int main ()
{
int t;
Double x1,x2,x3,y,y1,y2,y3;
scanf ("%d", &t);
while (t--)
{
x1=0;
x2=100;
scanf ("%lf", &y);
Y1=f (x1)-y;
Y2=f (x2)-y;
if (y1>0| | y2<0)
printf ("No solution!\n");
else
{
while (Fabs (f (x1)-F (x2)) >=0.00001)
{
x3= (x1+x2)/2
; Y3=f (x3)-y;
if (y3>0)
x2=x3;
else
x1=x3;
Y1=f (x1)-y;
Y2=f (x2)-y
;
printf ("%.4lf\n", x3);
}
}
return 0;
}