zoukankan      html  css  js  c++  java
  • 杭电1969--Pie(二分法)

    Pie

    Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 6442    Accepted Submission(s): 2421


    Problem 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
     

     

    Recommend
    wangye   |   We have carefully selected several similar problems for you:  2899 2446 2298 2333 1399 
    RE: 给出的是食物半径+(认真读题)
     1 #include <cmath>
     2 #include <cstdio>
     3 #include <iostream>
     4 #define PI acos(-1.0)
     5 //#define PI 3.1415926   不要用这个; 
     6 using namespace std;
     7 double num[10010];
     8 int main()
     9 {
    10     int t;
    11     scanf("%d", &t);
    12     while(t--)
    13     {
    14         int m, n;
    15         double max = 0.0;
    16         scanf("%d %d", &m, &n);
    17         n++;
    18         for(int i=0; i<m; i++)
    19         {
    20             int ti;
    21             scanf("%d",&ti);
    22             num[i] = PI*ti*ti; 
    23             if(num[i] > max)
    24                 max = num[i];
    25         }
    26         double min=0.0, mid;
    27         while(max - min > 1e-6)
    28         {
    29             mid=(max + min) / 2.0;
    30             int total = 0;
    31             for(int i=0; i<m; i++)
    32                 total += (int)(num[i] / mid);
    33             if(total >= n)
    34                 min = mid;
    35             else
    36                 max = mid;
    37         }
    38         printf("%.4lf
    ",mid);
    39     }
    40     return 0; 
    41 } 
     
  • 相关阅读:
    Algorithm Of Swift -- 4.合并两个有序数组
    Algorithm Of Swift -- 3.链表反转
    Algorithm Of Swift -- 2.字符串反转
    Algorithm Of Swift -- 1.两数之和
    1850984: Fix: crash when running am.jar without parameters
    微信公众号关联小程序,实现消息推送。
    NPOI根据Excel数据导入导出到Datatable中--帮助类
    OpenCvSharp+ZXing实现多个DataMatrix解析
    多数据源导致事务不生效
    android theme之Material的默认色和夜晚模式
  • 原文地址:https://www.cnblogs.com/soTired/p/4699077.html
Copyright © 2011-2022 走看看