hdu 2199 Can you solve this equation?

时间:2023-03-08 22:57:25
hdu 2199 Can you solve this equation?

hdu 2199 Can you solve this equation?

hdu 2199 Can you solve this equation?

#include<stdio.h>
#include<math.h>
double f(double x)
{
return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6;
}
int main(void)
{
int t;
double y,x1,x2,x3,y1,y2,y3;
scanf("%d",&t);
while(t--)
{
scanf("%lf",&y);
x1=0;
x2=100;
y1=f(x1)-y;
y2=f(x2)-y;
if(y1>0||y2<0)
{
printf("No solution!\n");
}
else
{
while(fabs(y1-y2)>=0.0001)
{
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("%0.4f\n",x3);
}
}
return 0;
}