• HDU1969


    记得用PI=acos(-1)反三角函数求,用一次排序,然后二分和贪心

    #include<iostream>
    #include<algorithm>
    #include<iomanip>
    #include<cmath>
    using namespace std;
    class Pie{
    public:
    double r;
    double s;
    };
    bool Check(Pie p[], int n, int f, double x);
    bool Cpm(Pie&a, Pie&b){
    return a.r>b.r;
    }
    int main(){
    Pie p[10001];
    int i, n, f, Case;
    double left, right, mid, pi =acos(-1);
    cin >> Case;
    while (Case--){
    cin >> n >> f;
    f++;
    for (i = 0; i < n; i++){
    cin >> p[i].r;
    p[i].s = p[i].r*p[i].r*pi; 
    }
    sort(p, p + n, Cpm); //按面积从小大大排序
    left = 0.0, right = p[0].s; //左右边界
    while (right - left>1e-5){
    mid = (left + right)/2;
    if (Check(p, n, f, mid))
    left = mid;
    else
    right = mid;
    }
    cout <<setiosflags(ios::fixed)<<setprecision(4)<<(left+right)/2<< endl;
    }
    return 0;
    }
    bool Check(Pie p[],int n,int f, double x){//检查是否可以满足条件
    int i = 0, peo = 0;
    for (i = 0; i < n; i++){
    peo += int(p[i].s / x);
    if (peo >=f)
    return 1;
    }
    return 0;
    }
  • 相关阅读:
    CodeForces 650C Table Compression
    HDU 5632 Rikka with Array [想法题]
    HDU 4352 XHXJ's LIS
    HDU 5634 Rikka with Phi
    HDU 4763 Theme Section
    LightOJ 1342 Aladdin and the Magical Sticks [想法题]
    HDU 4578 Transformation
    POJ 1177 Picture
    HDU 4614 Vases and Flowers
    SPOJ AEROLITE
  • 原文地址:https://www.cnblogs.com/td15980891505/p/4895174.html
Copyright © 2020-2023  润新知