HDU 2199 二分查找

来源:互联网 发布:js点击按钮执行ctrl c 编辑:程序博客网 时间:2024/05/17 21:59
#include<iostream>
#include<cstdio>
#include<cstring>
double m;
void sou(double n)
{
    double  hight=100.0,low=0.0,x;
    while(hight-low>1e-6)      //坑,样例能过WA,样例不过AC,HDU问题题
    {
        m=(hight+low)/2;
        x=8*m*m*m*m + 7*m*m*m + 2*m*m + 3*m + 6;
        if( x== n)
            return ;
        if(x>n)
            hight=m-(1e-7);    //可以到0和100
        if(x<n)
            low=m+(1e-7);
    }
}
int main()
{
    double n;
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf",&n);
        if(n<6||n>807020306)
            printf("No solution!\n");   //单调递增
        else
        {
            sou(n);
            printf("%.4lf\n",m);
        }
    }
    return 0;
}
0 0
原创粉丝点击