HDU 2199 Can you solve this equation?

题解:二分求解

HDU 2199 Can you solve this equation?
#include <cstdio>
#include <cmath>
using namespace std;

double f(double x)
{
    return(8*pow(x,4)+7*pow(x,3)+2*pow(x,2)+3*x+6);
}

int main()
{
    int t;
    double l,r,mid,yl,yr,y,y1;
    scanf("%d", &t);
    while(t--)
    {
        l=0;
        r=100;        
        scanf("%lf",&y1);   
        yl=f(l)-y1;
        yr=f(r)-y1;
        if (yl>0||yr<0)
            printf("No solution!\n");
        else{
            while (fabs(l-r)>=0.000000001)
            {
                mid=(l+r)/2;
                y=f(mid)-y1;
                if (y>=0) r=mid;
                else l=mid;
            }
            printf("%0.4lf\n",mid);
        }
    }
    return 0;
}
HDU 2199 Can you solve this equation?

HDU 2199 Can you solve this equation?

上一篇:广州Java培训之Java抽象类与接口的区别及用法


下一篇:使用window10系统搭建完善的Linux开发环境