分馅饼 Pie
2015-08-04 16:26
169 查看
Pie
链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/C
题目:
题意:
链接:
题目:
[align=left]ProblemDescription[/align] MybirthdayiscomingupandtraditionallyI'mservingpie.Notjustonepie,no,IhaveanumberNofthem,ofvarioustastesand ofvarioussizes.Fofmyfriendsarecomingtomypartyandeachofthemgetsapieceofpie.Thisshouldbeonepieceofonepie, notseveralsmallpiecessincethatlooksmessy.Thispiececanbeonewholepiethough. Myfriendsareveryannoyingandifoneofthemgetsabiggerpiecethantheothers,theystartcomplaining. Thereforeallofthemshouldgetequallysized(butnotnecessarilyequallyshaped)pieces,evenifthisleadsto somepiegettingspoiled(whichisbetterthanspoilingtheparty).Ofcourse,Iwantapieceofpieformyselftoo, andthatpieceshouldalsobeofthesamesize. Whatisthelargestpossiblepiecesizeallofuscanget?Allthepiesarecylindricalinshapeand theyallhavethesameheight1,buttheradiiofthepiescanbedifferent. |
[align=left]Input[/align] Onelinewithapositiveinteger:thenumberoftestcases.Thenforeachtestcase: ---OnelinewithtwointegersNandFwith1<=N,F<=10000:thenumberofpiesandthenumberoffriends. ---OnelinewithNintegersriwith1<=ri<=10000:theradiiofthepies. |
[align=left]Output[/align] Foreachtestcase,outputonelinewiththelargestpossiblevolumeVsuchthatmeandmyfriendscanallgetapiepieceofsizeV.Theanswershouldbegivenasafloatingpointnumberwithanabsoluteerrorofatmost10^(-3). |
[align=left]SampleInput[/align]3 33 433 124 5 105 1423456542 |
[align=left]SampleOutput[/align]25.1327 3.1416 50.2655 |
有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> usingnamespacestd; doublepi=acos(-1.0);//用反余弦求pi constintmaxn=10010; doublesum,y; intn,a[maxn],f; doubleb[maxn]; intxz(doublem) { intx=0,i; for(i=0;i<n;i++) { x+=(int)(b[i]/m); } if(x>=f+1) return1; elsereturn0; } 22voidslove() { doublel=0.0,r=y,mid=0; while((r-l)>1e-6)//精度问题 { mid=(l+r)/2; if(xz(mid))l=mid; elser=mid; } printf("%.4f\n",l); } intmain() { inti,t; cin>>t; while(t--) { sum=0.0; cin>>n>>f; for(i=0;i<n;i++) { cin>>a[i]; b[i]=a[i]*a[i]*pi; sum+=b[i]; } y=sum/(f+1); slove(); } return0; }
相关文章推荐
- 记住密码弹出事件
- poj 3620 Avoid The Lakes【简单dfs】
- neuoj 1117 Ready to declare
- Oracle APEX installation with ORDS
- 支付宝支付--手机支付
- Oracle Secure Global Desktop 与 EM12c的集成
- poj3301Texas Trip三分旋转角度
- Objective-C 的动态类型判断
- Window文件目录挂载(mount)到linux系统目录下
- 装饰模式与代理模式的区别(转载)
- 老菜鸟的自留地
- JavaScript异常错误处理
- register_shutdown_function捕获致命错误
- Android开发:使用Windows cmd窗口抓取Android手机log
- linux 远程桌面:SSH
- 简单实现UGUI拖拽功能
- Android 自定义View和ViewGroup实现密码图案
- 9.3栈和队列(五)——汉诺塔问题
- STL 优先队列的 优先级
- 根据经纬度获取地名,根据地名获取经纬度