题意:给出Y的值,求x的值
思路:x 是浮点型,枚举?不会。。用的是二分查找。
#include<iostream>
using namespace std;
double ans(double x)
{return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6;}
int main()
{
double Y,b,c,mid;
int N;
scanf("%d",&N);
while(N--)
{
scanf("%lf",&Y);
if(Y<ans(0)||Y>ans(100))
{
printf("No solution!\n");
continue;
}
b=0;c=100;
while(c-b>1e-10)
{
mid=(b+c)/2.0;
if(ans(mid)>Y) c=mid-(1e-10);
else if(ans(mid)<Y)b=mid+(1e-10);
}
printf("%.4f\n",mid);
}
}