• POJ 3122 pie (二分法)


    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 个朋友来参加我的生日party,m个蛋糕,我要把它平均分给每个人(包括我),并且每个人只能从一块蛋糕得到自己的那一份,并且分得的蛋糕大小要一样,形状可以不一样,每块蛋糕都是圆柱,高度一样。

     1 #include<cstdio>
     2 #include<math.h>
     3 double pi = acos(-1.0);
     4 double sum,mid,le,ri,b[10000+11],max0;
     5 int n,f,r;
     6 double fl(double x)
     7 {
     8     int su=0;
     9     for(int i = 0 ; i < n ; i++)
    10     {
    11         su+=(int)(b[i]/x);
    12     }
    13     return su;
    14 }
    15 int main()
    16 {
    17     int t;
    18     scanf("%d",&t);
    19     while(t--)
    20     {
    21         sum=0;
    22         scanf("%d %d",&n,&f);
    23         f++;
    24         for(int i = 0 ; i < n ; i++)
    25         {
    26             scanf("%d",&r);
    27             b[i]=r*r*pi;
    28             sum+=b[i];
    29         }
    30         sum=sum/f;
    31         le=0.0;
    32         ri=sum;
    33         while(fabs(ri-le)>1e-6)
    34         {
    35             mid=(le+ri)/2;
    36             if(fl(mid) >= f)
    37             {
    38                 le=mid;
    39             }
    40             else
    41             {
    42                 ri=mid;
    43             }
    44         }
    45         printf("%.4f
    ",le);
    46     }
    47 }
     
     
     
     
     
    ——将来的你会感谢现在努力的自己。
  • 相关阅读:
    sqlserver 脚本生成数据库文档
    在命令行中执行kms命令激活Microsoft Office 2010
    .NET Core项目修改project.json来引用其他目录下的源码等文件的办法 & 解决多框架时 project.json 与 app.config冲突的问题
    asp.net 访问局域网共享文件
    Winform开发框架的重要特性总结
    Winform开发框架之插件化应用框架实现
    Winform开发框架之权限管理系统的改进
    Winform开发框架之统计图表的实现
    在Winform开发框架中实现对数据库的加密支持
    Winform开发框架之通用高级查询模块
  • 原文地址:https://www.cnblogs.com/yexiaozi/p/5710982.html
Copyright © 2020-2023  润新知