现在的位置: 首页 > 综合 > 正文

hdu2199 Can you solve this equation?

2018年12月21日 ⁄ 综合 ⁄ 共 413字 ⁄ 字号 评论关闭

http://acm.hdu.edu.cn/showproblem.php?pid=2199


二分求单调方程的解。

#include <stdio.h>
#include <math.h>
double L, R, M;
int T;
double Y;
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()
{
    scanf("%d", &T);
    while(T--) {
        scanf("%lf", &Y);
        if(f(0) <= Y && Y<= f(100)) {
             L = 0; R = 100;
             while(R - L >1e-10) {
                M = (L +R)/2;
                double ans = f(M);
                if(ans > Y) {
                    R = M - 1e-12;
                }else
                    L = M + 1e-12;
             }
             printf("%.4lf\n", (L + R)/2);
        }else
            printf("No solution!\n");
    }
    return 0;
}

【上篇】
【下篇】

抱歉!评论已关闭.