首页 > 其他 > 详细

Hdu 2199 Can you solve this equation?

时间:2014-02-01 11:57:30      阅读:441      评论:0      收藏:0      [点我收藏+]

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2199

bubuko.com,布布扣
//二分法求零点

#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int t;
double x,y;
//f(x)递增
double f(double x){
    return 8*pow(x,4)+7*pow(x,3)+2*x*x+3*x+6-y;
}
double lt,rt,mid;
double tmp;
double ans;
int main (){

    cin>>t;
    while(t--){

        cin>>y;
        if(y<6)  //f(0)>0
            cout<<"No solution!"<<endl;
        else if(f(100)<0)
            cout<<"No solution!"<<endl;
        else{
            lt=0;
            rt=100;
            while(rt-lt>1e-8)
            {
                mid=(lt+rt)/2;
                tmp=f(mid);
                if(tmp>0)
                    rt=mid;
                else if(tmp<0)
                    lt=mid;
                else
                    rt=lt=mid;
            }
            ans=mid;
            cout<<fixed<<setprecision(4);
            cout<<mid<<endl;
        }
    }
    return 0;
}
bubuko.com,布布扣

Hdu 2199 Can you solve this equation?

原文:http://www.cnblogs.com/neverchanje/p/3536762.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!