NYOJ 503 & HDU 2199 解方程(二分)

来源:互联网 发布:软件著作权和商标 编辑:程序博客网 时间:2024/05/21 19:29

题目链接:Click here~~

二分查找。注意精度。

#include <stdio.h>#include <math.h>double f(double x){    return 8*pow(x,4) - 7*pow(x,3) + 2*pow(x,2) + 3*x + 6;}double Binary_Find(double left,double right,double y){    while(right-left>1e-7)    {        double mid=(left+right)/2;        if(f(mid) < y)            left  = mid;        else            right = mid;    }    return left;}int main(){    int z;    double y;    scanf("%d",&z);    while(z--)    {        scanf("%lf",&y);        if(f(0)>y || f(100)<y)            puts("No solution!");        else            printf("%.4lf\n",Binary_Find(0,100,y));    }    return 0;}


原创粉丝点击