zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    java之this关键字
    单位转换类UnitUtil2
    重量WeightFormatUtil辅助类
    语音提示辅助类MySoundAlertUtil
    Android 编程下 Touch 事件的分发和消费机制
    switch case语句的用法
    Struts2之环境配置
    CSS属性绘制图形(一)
    jquery $(document).ready() 与window.onload的区别
    Android开发之ActionBar
  • 原文地址:https://www.cnblogs.com/moonbay/p/2751246.html
Copyright © 2011-2022 走看看