zoukankan      html  css  js  c++  java
  • hdu 2199 Can you solve this equation? (二分)

    简单二分查找,应该属于水题了吧...纠结的是样例没过,一试竟然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 ;
    }

  • 相关阅读:
    开不了的窗_____window.open
    IIS项目发布完整流程
    理解MVC模式
    ASP.NET MVC 基础(01)
    C#之线程和并发
    vue时间格式化
    windows 2013 datacenter 安装sql server2008 r2兼容性
    SQL Server DBA十大必备工具使生活轻松
    ORACLE主要的系统表和系统视图
    Oracle中spool命令实现的两种方法比较
  • 原文地址:https://www.cnblogs.com/xiaolongchase/p/2351919.html
Copyright © 2011-2022 走看看