您的位置:首页 > 其它

分馅饼 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;
}




                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: