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 } 
     
  • 相关阅读:
    实验一 总结
    C#中将JObject类型数据转换成这样的货币数字-带千分符-四舍五入2位小数
    Git常用命令+报错solution
    Python Requests学习笔记
    Python requests 环境搭建
    关于Page Object个人结合测试框架的一些理解
    REST理解 + API测试学习笔记
    记录组内做API测试的流程
    理解c#的Get Set访问器及测试脚本中的应用
    tp3
  • 原文地址:https://www.cnblogs.com/soTired/p/4699077.html
Copyright © 2011-2022 走看看