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

简单二分查找,应该属于水题了吧...纠结的是样例没过,一试竟然AC。

这两天状态太差了,发生这么多事,有点不知所措的感觉。现在都过去了,感觉还是挺烦燥...只能从头加深下搜索了。

 

code:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
using namespace std ;
double y ;
double l, r, m ;
double slove(double x){
    return 8*pow(x, 4.0) + 7*pow(x, 3.0) + 2*pow(x, 2.0) + 3*x + 6 ;
}
int main() {
    int t ;
    scanf("%d", &t) ;
    while(t--){
        scanf("%lf", &y) ;
        if(slove(0)<=y&&y<=slove(100)){
            l = 0 ;
            r = 100 ;
            while(r-l>1e-6){    //要求 accurate up to 4 decimal places
                                
//所以计算时要精确到1e-5,最低精度1e-6
                m = (l + r) / 2 ;
                double ans = slove(m) ;
                if(ans>y)
                    r = m ;
                else
                    l = m ;
            }
            printf("%.4lf\n", (l+r)/2) ;
        }else
            printf("No solution!\n") ;
    }
    return 0 ;
}

posted on 2012-02-14 22:42  追逐.  阅读(178)  评论(0编辑  收藏  举报