zoukankan      html  css  js  c++  java
  • hdu 2199又是一道二分答案的题

    这都是今天做的第三道二分答案的题了。。。这题精度控制要求也比较高,我是把eps设成1e-8才过的1e-6都过不了。。。

    /*
     * hdu2199/win.cpp
     * Created on: 2012-11-2
     * Author    : ben
     */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    #include <stack>
    #include <string>
    #include <vector>
    #include <deque>
    #include <list>
    #include <functional>
    #include <numeric>
    #include <cctype>
    using namespace std;
    const double eps = 0.00000001;
    const double LOW = 6 - eps;
    const double HIGH = 807020306 + eps;
    inline double getresult(double x) {
        double xx = x * x;
        double xxxx = xx * xx;
        return 8 * xxxx + 7 * x * xx + 2 * xx + 3 * x + 6;
    }
    double getans(double y) {
        double low = 0, high = HIGH, mid;
        while(high - low > eps) {
            mid = (low + high) / 2;
            if(getresult(mid) - y < eps) {
                low = mid;
            }else {
                high = mid;
            }
        }
        return mid;
    }
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("data.in", "r", stdin);
    #endif
        int T;
        double y;
        scanf("%d", &T);
        while(T--) {
            scanf("%lf", &y);
            if(y < LOW || y > HIGH) {
                puts("No solution!");
                continue;
            }
            double ans = getans(y);
            printf("%.4f\n", ans);
        }
        return 0;
    }
  • 相关阅读:
    NodeJS优缺点
    移动端触摸相关事件touch、tap、swipe
    vscode使用技巧
    js 字符串转数字
    js 导出Excel
    <!--[if IE 9]> <![endif]-->
    js 异步请求
    关于windows串口处理
    mfc 托盘提示信息添加
    微软的麦克风处理示列代码
  • 原文地址:https://www.cnblogs.com/moonbay/p/2751732.html
Copyright © 2011-2022 走看看