hdu2199 Can you solve this equation? (二分搜索)

#include <stdio.h>
#include <math.h>

int func(double x)
{
	return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6;
}

int main()
{
	int n;
	double left,right,mid,Y;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%lf",&Y);
		if(Y>func(100)||Y<func(0))
			printf("No solution!\n");
		else
		{
			right=100.0;
			left=0.0;
			while((right-left)>1e-8)
			{
				mid=(left+right)/2.0;
				if(func(mid)<Y)
					left=mid;
				else
					right=mid;
			}
			printf("%.4lf\n",left);
		}
	}
	return 0;
}

你可能感兴趣的:(hdu2199 Can you solve this equation? (二分搜索))