zoukankan      html  css  js  c++  java
  • poj 3122(二分查找)

    Pie
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 13564   Accepted: 4650   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<cstdio>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<cmath>
     7 #include<vector>
     8 #include<iomanip>
     9 #include<queue>
    10 #include<stack>
    11 using namespace std;
    12 #define N 10000
    13 #define PI 3.1415926535897932384626
    14 double r[N],v,d,c,ma;
    15 int main(){
    16     //freopen("in.txt","r",stdin);
    17     std::ios::sync_with_stdio(false);
    18     cin>>c;
    19     while(c--){
    20         int n,f;
    21         cin>>n>>f;
    22         f++;
    23         ma=0.0;
    24         for(int i=0;i<n;i++){
    25             cin>>r[i];
    26             r[i]*=r[i];
    27             if(ma<r[i]) ma=r[i];
    28         }
    29         double up,low,mid;
    30         low=0.0;up=ma;
    31         while(up-low>1e-6){
    32             mid=(up+low)/2;
    33             int num=0;
    34             for(int i=0;i<n;i++)
    35                 num+=(int)(r[i]/mid);
    36             if(num>=f)
    37                 low=mid;
    38             else
    39                 up=mid;
    40         }
    41         cout<<fixed<<setprecision(4)<<mid*PI<<endl;
    42     }
    43     return 0;
    44 }
  • 相关阅读:
    git 拉取远程代码 git branch -vv --all
    常用命令统计
    topology key
    gstreamer 相关直播源(rtmp rtsp)
    汉诺塔问题 最简单的图文讲解递归实现
    RTP 用ffmpeg
    kurento + nodejs 开源项目 webRTC 转成 RTMP输出
    RTP SDP 详解 RTCP 附带说了一下SRTP RTSP
    RxSwiftCommunity/Action使用介绍
    zsh Shell 增加自动补全、语法高亮
  • 原文地址:https://www.cnblogs.com/yoyo-sincerely/p/5029735.html
Copyright © 2011-2022 走看看