• hdu1969Pie(根据体积二分,分馅饼)


    Pie

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


    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

    f个人分n个圆柱形的馅饼,要求每人分到的馅饼体积相同,可以切割馅饼,但分给每个人的不能是零碎的,分给一个人的只能是从同一块上切下来的。最后输出每个人分到的体积。

    可以根据体积二分来找到答案的体积。体积最小是0,(都没吃到),最大是馅饼总体积/总人数 (理想情况)。每次二分看该体积分的话可以分给多少人,如果可以分的人数大于等于f+1(因为自己也要吃),就把中间值赋给左边界。否则就赋给右边界。一直这样二分下去。直到r-l足够小

    写得有点啰嗦。推荐https://blog.csdn.net/qq_36731677/article/details/54971485

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 double a[10005];
     4 void init()
     5 {
     6     for(int i=0;i<1005;i++)
     7     {
     8         a[i]=0.0;
     9     }
    10 }
    11 int main()
    12 {
    13     int t;
    14     while(~scanf("%d",&t))
    15     {
    16         while(t--)
    17         {
    18             init();
    19             int n,f;double sum=0;
    20             scanf("%d %d",&n,&f);
    21             for(int i=0;i<n;i++)
    22             {
    23                 scanf("%lf",&a[i]);
    24                 a[i]=acos(-1.0)*a[i]*a[i];
    25                 sum=sum+a[i];
    26                 
    27             }
    28             //根据每个人分到的体积二分,最小是0,最大是馅饼总体积/总人数 
    29             double l=0.0,r=acos(-1.0)*sum,mid=(l+r)/2.0;
    30             while(r-l>1e-6)//精度不要设太高,容易t,也不要太低,适中 
    31             {
    32                 int temp=0;
    33                 for(int i=0;i<n;i++)
    34                 {
    35                     temp=temp+(int)(a[i]/mid);
    36                 }
    37                 if(temp>=f+1)
    38                 {
    39                     l=mid;
    40                     mid=(l+r)/2.0;
    41                 }
    42                 if(temp<f+1)
    43                 {
    44                     r=mid;
    45                     mid=(l+r)/2.0;
    46                 }
    47                 
    48             }
    49             printf("%.4lf
    ",mid);
    50         }
    51         
    52     }
    53     return 0;
    54 }
  • 相关阅读:
    C#RSA的研究,C#、Java互通
    .NetCore接入Log4Net
    asp.net core 5.0 使用log4net
    C# 根据出生年月 计算天数/计算X岁X月X天字符串
    DateTime? 转对象出错的问题
    WPF新的窗口返回值的方式
    C# Post
    数据库跨服务器更新表内容
    sql server 初学乱记
    sql server 2008/k3 cloud 安装踩雷
  • 原文地址:https://www.cnblogs.com/fqfzs/p/9943907.html
Copyright © 2020-2023  润新知