题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=2199
#include <bits/stdc++.h>
using namespace std;
double Y;
double h, r, m;
double f( double x )
{
return 8*pow(x, 4.0) + 7*pow(x, 3.0) + 2*pow(x, 2.0) + 3*x + 6;
}
int main(void)
{
int t;
scanf("%d", &t );
//浮点数很重要
while( t-- )
{
scanf("%lf", &Y );
if( f(0) <= Y && Y <= f(100) )
{
h = 0;
r = 100;
while( r - h > 1e-6 )
{
m = (h + r) / 2; //折半
double ans = f(m);
if( ans > Y )
{
r = m - 1e-7;
}else
h = m + 1e-7;
}
printf("%.4lf\n", (h + r) / 2 );
}else
printf("No solution!\n");
}
return 0;
}