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

 #include<bits/stdc++.h>
using namespace std;
double a[];
void init()
{
for(int i=;i<;i++)
{
a[i]=0.0;
}
}
int main()
{
int t;
while(~scanf("%d",&t))
{
while(t--)
{
init();
int n,f;double sum=;
scanf("%d %d",&n,&f);
for(int i=;i<n;i++)
{
scanf("%lf",&a[i]);
a[i]=acos(-1.0)*a[i]*a[i];
sum=sum+a[i]; }
//根据每个人分到的体积二分,最小是0,最大是馅饼总体积/总人数
double l=0.0,r=acos(-1.0)*sum,mid=(l+r)/2.0;
while(r-l>1e-)//精度不要设太高,容易t,也不要太低,适中
{
int temp=;
for(int i=;i<n;i++)
{
temp=temp+(int)(a[i]/mid);
}
if(temp>=f+)
{
l=mid;
mid=(l+r)/2.0;
}
if(temp<f+)
{
r=mid;
mid=(l+r)/2.0;
} }
printf("%.4lf\n",mid);
} }
return ;
}

hdu1969Pie(根据体积二分,分馅饼)的更多相关文章

  1. 分馅饼 Pie

    Pie 链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/C 题目: Problem Description ...

  2. POJ3122Pie(二分)

    http://poj.org/problem?id=3122 题意 :这个题最主要的就是审题要仔细,翻译不要漏句子.题目讲的是我要过生日,要给好友分馅饼(还有自己也想要一块),怕引起不公,所以每个人大 ...

  3. PIE(二分) 分类: 二分查找 2015-06-07 15:46 9人阅读 评论(0) 收藏

    Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...

  4. hdu 5954 -- Do not pour out(积分+二分)

    题目链接 Problem Description You have got a cylindrical cup. Its bottom diameter is 2 units and its heig ...

  5. [SinGuLaRiTy] 分治题目复习

    [SInGuLaRiTy-1025] Copyrights (c) SinGuLaRiTy 2017. All Rights Reserved. [POJ 1905] 棍的膨胀 (Expanding ...

  6. ACM pie

    我的生日快到了,传统上我正在做馅饼.不只是一个馅饼,不,我有N个,各种口味和各种尺寸. 数量为F我的朋友会来到我的聚会,每个人都得到一个馅饼. 这应该是一块馅饼,而不是几个小块,因为看起来很乱.这一块 ...

  7. HDU1969 Pie(二分搜索)

    题目大意是要办生日Party,有n个馅饼,有f个朋友.接下来是n个馅饼的半径.然后是分馅饼了, 注意咯自己也要,大家都要一样大,形状没什么要求,但都要是一整块的那种,也就是说不能从两个饼中 各割一小块 ...

  8. IC 小常识

    IC产品的命名规则: 大部分IC产品型号的开头字母,也就是通常所说的前缀都是为生产厂家的前两个或前三个字母,比如:MAXIM公司的以MAX为前缀,AD公司的以AD为前缀,ATMEL公司的以AT为前缀, ...

  9. DO-214 SMA、SMB、SMC封装

    DO-214 is a standard that specifies a group of semiconductor packages for surface mounted diodes. Th ...

随机推荐

  1. C++中rapidxml用法及例子(源码)

    rapidxml是一个快速的xml库,比tinyxml快了50-100倍.本文给出创建.读取.写入xml的源码.      由于新浪博客不支持文本文件上传,在使用下面代码需要先下载 rapidxml, ...

  2. tomcat快速部署War包操作

    Linux快速部署War包操作,暂时是最简单的操作 1.先关闭Tomcat /home/java/tomcat7/bin/shutdown.sh 2.进入War包存放目录(可以通过工具:SSH Sec ...

  3. 使用命令导入、导出mysql数据

    1.导出全部数据库 利用mysqldump的—all-databases参数可以一口气把你数据库root用户下的所有数据库一口气导出到一个sql文件里.然后,重装系统后使用source命令可以再一口气 ...

  4. 学生会管理系统(SSM)vue+ssm+shiro

    数据库 drop database StudentUnionManagementSystem ; create database StudentUnionManagementSystem CHARAC ...

  5. ssm分页

    pom.xml配置文件中增加相关的插件. <dependency> <groupId>com.github.pagehelper</groupId> <art ...

  6. localtunnel内网服务器暴露至公网

    摘自@scarlex   1.安装 npm install -g localtunnel 2.运行 lt --port 8080  (your url is: http://xxxx.localtun ...

  7. 绘图驱动-OSD原理1

    OSD(On Screen Display)是屏幕显示技术的一种,用于在显示终端上显示字符.图形和图像.实现的过程为:存储器(一般为内存的一段)的内容与显示终端上的像素一一对应.这种一一对应的关系一般 ...

  8. MAMP:MySQL wasn't able to start

    MAMP 我点击start server的时候 发现mysql服务器打不开 http://images.cnblogs.com/cnblogs_com/lwwen/1231721/o_11111111 ...

  9. git获取步骤

    $ git init $ git config --global user.name "[name]" $ git config --global user.email [emai ...

  10. Win7配置express4环境

    本机环境: $ node -v v10.14.1 $ npm -v 6.4.1 配置node环境变量: #配置全局安装目录 npm config set prefix "G:\WEB\nod ...