• hdu 1969二分答案


    算水题吧,不过这题精度卡得还是挺厉害的,刚开始的时候我是把面积都放大,放大100000000倍,都用long long进行处理,还是过不了,只能用double控制精度了。

    /*
     * hdu1969/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.000001;
    const double pi = acos(-1);
    const int MAXN = 10009;
    int N, F;
    double data[MAXN];
    
    inline bool judge(double ans) {
        int t = 0;
        for(int i = 0; i < N; i++) {
            t += (int)(data[i] / ans);
        }
        return t >= F;
    }
    
    double getans() {
        double low = 0, mid;
        double high = *max_element(data, data + N);
        while(high - low > eps) {
            mid = (low + high) / 2;
            if(judge(mid)) {
                low = mid;
            }else {
                high = mid;
            }
        }
        return mid;
    }
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("data.in", "r", stdin);
    #endif
        int T, a;
        scanf("%d", &T);
        while(T--) {
            scanf("%d%d", &N, &F);
            F++;
            for(int i = 0; i < N; i++) {
                scanf("%d", &a);
                data[i] = pi * a * a;
            }
            printf("%.4f\n", getans());
        }
        return 0;
    }
  • 相关阅读:
    字符串面试题:将句子的单词序倒置
    字符串面试题:将整型转换为字符串
    QML定时器
    QML按键事件处理
    QML鼠标事件实现变色矩形
    QML动态加载组件
    QML鼠标区域控制
    属性绑定与赋值
    设置虚拟机的本地端口映射
    关于修改banner信息;nginx反向代理apache应用
  • 原文地址:https://www.cnblogs.com/moonbay/p/2751246.html
Copyright © 2020-2023  润新知