2021-04-05

2899

#include
using namespace std;
double f(double x,double y)
{
     
	double f=(x*(x*(x*(x*(x*(x*(x*6+8)))+7)+5)-y));
	return f;}
double slove(double l,double r,double y){
     
	double lm,rm;
	while(r-l>pow(10,-6)){
     
		lm=(2*l+r)/3;
		rm=(l+2*r)/3;
		if(f(lm,y)>f(rm,y))l=lm;
		else if(f(lm,y)<f(rm,y))r=rm;
		else l=lm,r=rm;
	}
	return f((l+r)/2,y);
}
int main()
{
     
	double y;
	int n;
	scanf("%d",&n);
	while(n--){
     
		scanf("%lf",&y);
		printf("%.4f\n",slove(0.0,100.0,y));
	}
	return 0;
}

你可能感兴趣的:(2021-04-05)