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;
    }
  • 相关阅读:
    ES6常用语法
    nodejs中exports与module.exports的区别
    CSS animation动画
    CSS user-select文本是否可复制
    VUE 滚动插件(better-scroll)
    VUE 父组件与子组件交互
    CSS div内文字显示两行,超出部分省略号显示
    linux下使用tar命令
    linux fdisk命令使用
    关于SUID、SGID、Sticky
  • 原文地址:https://www.cnblogs.com/moonbay/p/2751732.html
Copyright © 2011-2022 走看看