分馅饼 Pie
Pie
链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/C
题目:
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
|
Sample Output
|
题意:
- 有n个馅饼,有f个朋友,接下来是n个馅饼的半径。然后是分馅饼,
要求大家都要一样大,形状没什么要求,但都要是一整块的那种,也就说不能从两个饼中
各割一小块来凑一块。
题目要求我们分到的饼尽可能的大。- 分析:
用二分法查找,
- 把0设为l,把y设为r。mid=(l+r)/2;
- 以mid为标志,如果所有的饼可以分割出f+1《还有自己》个mid,那么返回1,说明每个人可以得到的饼的体积可以
- 大于等于mid;如果不能分出这么多的mid,那么返回0,说明每个人可以得到饼的体积小于mid。
- 注意精度
- 代码:
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<cmath>
- using namespace std;
- double pi=acos(-1.0); //用反余弦求pi
- const int maxn=;
- double sum,y;
- int n,a[maxn],f;
- double b[maxn];
- int xz(double m)
- {
- int x=,i;
- for(i=;i<n;i++)
- {
- x+=(int)(b[i]/m);
- }
- if(x>=f+)
- return ;
- else return ;
- }
- 22 void slove()
- {
- double l=0.0,r=y,mid=;
- while((r-l)>1e-) //精度问题
- {
- mid=(l+r)/;
- if(xz(mid)) l=mid;
- else r=mid;
- }
- printf("%.4f\n",l);
- }
- int main()
- {
- int i,t;
- cin>>t;
- while(t--)
- {
- sum=0.0;
- cin>>n>>f;
- for(i=;i<n;i++)
- {
- cin>>a[i];
- b[i]=a[i]*a[i]*pi;
- sum+=b[i];
- }
- y=sum/(f+);
- slove();
- }
- return ;
- }
分馅饼 Pie的更多相关文章
- hdu1969Pie(根据体积二分,分馅饼)
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- [SinGuLaRiTy] 分治题目复习
[SInGuLaRiTy-1025] Copyrights (c) SinGuLaRiTy 2017. All Rights Reserved. [POJ 1905] 棍的膨胀 (Expanding ...
- 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 ...
- ACM pie
我的生日快到了,传统上我正在做馅饼.不只是一个馅饼,不,我有N个,各种口味和各种尺寸. 数量为F我的朋友会来到我的聚会,每个人都得到一个馅饼. 这应该是一块馅饼,而不是几个小块,因为看起来很乱.这一块 ...
- poj3122--二分加贪心
大致题意: 就是公平地分披萨pie 我生日,买了n个pie,找来f个朋友,那么总人数共f+1人 每个pie都是高为1的圆柱体,输入这n个pie的每一个尺寸(半径),如果要公平地把pie分给每一个人(就 ...
- POJ 3122 Pie(二分+贪心)
Pie Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22684 Accepted: 7121 Special Ju ...
- HDU1969 Pie(二分搜索)
题目大意是要办生日Party,有n个馅饼,有f个朋友.接下来是n个馅饼的半径.然后是分馅饼了, 注意咯自己也要,大家都要一样大,形状没什么要求,但都要是一整块的那种,也就是说不能从两个饼中 各割一小块 ...
- POJ3122Pie(二分)
http://poj.org/problem?id=3122 题意 :这个题最主要的就是审题要仔细,翻译不要漏句子.题目讲的是我要过生日,要给好友分馅饼(还有自己也想要一块),怕引起不公,所以每个人大 ...
- Android系统概述
一.Android的诞生 Android这一词最先出现在法国作家利尔亚当在1886年发表的科幻小说<未来夏娃>中,作者将外表像人类的机器起名为Android,这也就是Android小人名字 ...
随机推荐
- Thinkphp 解决写入配置文件的方法
在/Application/Common/Common创建function.php,然后添加以下代码: <?php /** * [writeArr 写入配置文件方法] * @param [typ ...
- hdu 5294 最短路+最大流 ***
处理处最短路径图,这个比较巧妙 链接:点我
- Eclipse的详细安装步骤
第一种:这个方法是在线安装的 第二种:下载完整免安装包 首先打开网址:http://www.eclipse.org/ 然后在这里我就选择64位的安装,就以安装安卓开发的举例: 然后下载即可:
- h5嵌入视频遇到的bug及总结---转载
最近做的一个h5活动因为嵌入视频而发现了好多以前从未发现的问题,在测试的时候不同系统不同版本不同环境等多多少少都出现了些问题,搞得我也是焦头烂额的,不过好在最终问题都解决了,自己也学到了好多东西,为了 ...
- Linux学习笔记(23) Linux备份
1. 备份概述 Linux系统需要备份的数据有/root,/home,/var/spool/mail,/etc及日志等其他目录. 安装服务的数据需要备份,如apache需要备份的数据有配置文件.网页主 ...
- 【tomcat 无法部署】svn上下载的maven项目无法部署到tomcat中
问题: svn上下载的maven项目无法部署到tomcat中,tomcat不识别项目,但是这个项目确实是web项目 发现的过程: 然后依次产看项目的编译版本: 项目的依赖架包: 才发现: 解决方法: ...
- HTML5 重要标签及其属性学习
1.google字体:<link href="https://fonts.googleapis.com/css?family=Lobster" rel="style ...
- js整理3
函数 call: fun.call(a), a会转化成相应的对象,函数内的this即指向它; function foo() { console.log(this); } foo.call(null); ...
- IconFont和FontAwesome的区别?
一.[Iconfont] Iconfont支持所有低版本浏览器: Iconfont的图标库更大: Iconfont可以用自己上传的svg,但是要花费大量时间和耐心去设计AI图标: Iconfont的使 ...
- web开发的基础知识:http请求
引用自:http://blog.csdn.net/yefan2222/article/details/6198098 http://baike.baidu.com/view/1628025.htm?f ...