03-1

来源:互联网 发布:网络剧错生哔哩哔哩 编辑:程序博客网 时间:2024/06/13 10:37
/*
  title:
  问题分类:

*/

科学计数法1e-3

判断边界


http://www.patest.cn/contests/mooc-ds/03-1

#include<stdio.h>
#include<math.h>
double a1,a2,a3,a4;
double f(double x){
    return a1*pow(x,3)+a2*pow(x,2)+a3*x+a4;
}
int main(){
    freopen("in.txt","r",stdin);
    while(scanf("%lf %lf %lf %lf",&a1,&a2,&a3,&a4)!=EOF){
        double low,high;
        scanf("%lf %lf",&low,&high);
        if(f(low)==0){
            printf("%.2lf\n",low);
            continue;
        }else if(f(high)==0){
            printf("%.2lf\n",high);
            continue;
        }
        while(high-low>1e-3){
            if(f(low)*f(high)<0){
                double mid=(low+high)/2;
                if(f(mid)*f(low)>0){
                    low=mid;
                }else if(f(mid)*f(high)>0){
                    high=mid;
                }
            }
        }
        printf("%.2lf\n",(low+high)/2);
    }
    return 0;
}
0 0
原创粉丝点击