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. window使用结束进程

    在cmd中输入下面信息: 1. 查看所有进程占用的端口 :netstat -ano 2.查看占用指定端口的程序:netstat –ano|findstr 指定端口号 3.杀死相关的进程: 方法一:使用 ...

  2. VC MFC工具栏(CToolBar)控件(转)

    工具栏 工具栏控件在控件面板里没有对应的选项(图标),但有一个工具栏控件类CToolBar,所以我们如果要创建一个工具栏控件并显示在窗口里的话,只能用代码来完成,事实上任何一种控件,都可以用代码创建, ...

  3. ARM 汇编指令集 特点之一:条件执行后缀

    mov r0,r1; moveq r0,r1;//这句代码是否执行 取决于 上几句代码 的运行结果(最后一次CPSR 寄存器 的 高四位   NZCV 的标志位) 条件后缀执行特点:1.条件后缀执行是 ...

  4. 协议类接口 - SPI

     一.SPI概述 SPI(Serial Peripheral Interface,串行外设接口)总线系统是一种同步串行外设接口,它可以使CPU与各种外围设备以串行方式进行通信以交换信息.一般主控SoC ...

  5. GPUImage源码解读之GPUImageFramebufferCache

    简介 由于GPUImage添加滤镜可以形成一个FilterChain,因此,在渲染的过程中,可能会需要很多个FrameBuffer,但是正如上文所说,每生成一个FrameBuffer都需要占用一定的内 ...

  6. 【Django笔记三】Django2.0配置mysql模型

    一.环境版本信息: 操作系统:windows10 Django版本:2.0.5 Python版本:3.6.4 Mysql版本: 5.5.53   安装mysql 二.安装Mysqlclient: 1. ...

  7. 【模板】RMQ(计算区间最值)

    ①一维RMQ (1) dp[i,j] 表示从第i个数起连续2j个数中的(最大值min.最小值max.最大公约数gcd……),通过更改下列代码中的红色函数即可实现. (2) b数组放置所需查询的数列. ...

  8. Filebeat使用模块收集日志

    1.先决条件 在运行Filebeat模块之前: 安装并配置Elastic stack 完成Filebeat的安装 检查Elasticsearch和Kibana是否正在运行,以及Elasticsearc ...

  9. JavaScript脚本加载相关知识

    <script>标签的位置 HTML4规范允许<script>可以放在<head>或<body>中. 但是,放在<head>中会导致性能问题 ...

  10. python教程(二)·变量

    什么是变量?在百度百科中,变量的解释是: 变量来源于数学,是计算机语言中能储存计算结果或能表示值抽象概念.变量可以通过-- 这是一段很长很长的解释,其实,作者认为没必要这么机械式的去理解.简单说,变量 ...