hdu2199

典型的二分。。。然而当初 搞了一上午

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
double Y;
double cal(double x)
{
  return 8.0*x*x*x*x+7.0*x*x*x+2.0*x*x+3.0*x+6.0;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lf",&Y);
        if(Y<6||Y>807020306)
        {
            printf("No solution!\n");
            continue;
        }
        double l=0.0,r=100.0,mid;
        while(r-l>1e-8)
        {
            mid=(l+r)*0.5;
            if(cal(mid)>Y)
            {
                r=mid;
            }
            else
            {
                l=mid+1e-8;
            }
        }
        printf("%.4lf\n",mid);
    }
}

你可能感兴趣的:(hdu2199)