• Pie(浮点数二分)


    Pie

    http://poj.org/problem?id=3122

    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 24544   Accepted: 7573   Special Judge

    Description

    My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my party and each of them gets a piece of pie. This should be one piece of one pie, not several small pieces since that looks messy. This piece can be one whole pie though. 

    My friends are very annoying and if one of them gets a bigger piece than the others, they start complaining. Therefore all of them should get equally sized (but not necessarily equally shaped) pieces, even if this leads to some pie getting spoiled (which is better than spoiling the party). Of course, I want a piece of pie for myself too, and that piece should also be of the same size. 

    What is the largest possible piece size all of us can get? All the pies are cylindrical in shape and they all have the same height 1, but the radii of the pies can be different.

    Input

    One line with a positive integer: the number of test cases. Then for each test case:
    • One line with two integers N and F with 1 ≤ N, F ≤ 10 000: the number of pies and the number of friends.
    • One line with N integers ri with 1 ≤ ri ≤ 10 000: the radii of the pies.

    Output

    For each test case, output one line with the largest possible volume V such that me and my friends can all get a pie piece of size V. The answer should be given as a floating point number with an absolute error of at most 10−3.

    Sample Input

    3
    3 3
    4 3 3
    1 24
    5
    10 5
    1 4 2 3 4 5 6 5 4 2

    Sample Output

    25.1327
    3.1416
    50.2655

    Source

     
    浮点数二分写法
     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 #include<algorithm>
     5 #include<cmath>
     6 #include<queue>
     7 #include<vector>
     8 #define PI acos(-1.0)
     9 using namespace std;
    10 
    11 int n,m;
    12 double a[10005];
    13 
    14 bool erfen(double r){
    15     int sum=0;
    16     for(int i=1;i<=n;i++){
    17         sum+=int(a[i]/r);
    18     }
    19     if(sum>=m+1) return true;
    20     return false;
    21 }
    22 
    23 int main(){
    24     int T;
    25     scanf("%d",&T);
    26     while(T--){
    27         scanf("%d %d",&n,&m);
    28         double L=0,R=0;
    29         for(int i=1;i<=n;i++){
    30             scanf("%lf",&a[i]);
    31             a[i]*=a[i];
    32             if(a[i]>R) R=a[i];
    33         }
    34         while(R-L>0.00001){
    35             double mid=(L+R)/2;
    36             if(erfen(mid)){
    37                 L=mid;
    38             }
    39             else{
    40                 R=mid;
    41             }
    42         }
    43         printf("%.4f
    ",PI*L);
    44     }
    45     system("pause");
    46 }
    View Code
  • 相关阅读:
    ES6基础之——Set
    ES6基础之——继承extends
    ES6基础之——静态方法staitc
    ES6基础之——get 与 set
    ES6基础之——Class类
    ES6基础之——生成器Generators
    ES6基础之——迭代器Iterators
    ES6基础之——指向当前对象的原型对象 super
    ES6基础之——__proto__
    Vue慕课网音乐项目随手记--node代理及数据抓取
  • 原文地址:https://www.cnblogs.com/Fighting-sh/p/10031545.html
Copyright © 2020-2023  润新知