Pie
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6158 Accepted Submission(s):
2343
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.
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.
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).
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define PI acos(-1.0)//PI的精度最好大点
using namespace std; double L[] , man;
int n,k,i; bool F(double x)
{
int sum=;
for(i=;i<n;i++)
sum+=(int)(L[i]/x);//sum的作用是记录当要求的面积为x时,最多能分多少整块
return sum>=(k+);//如果能分的比要求的多就返回真
}
void qw()
{
double l=,r=man,mid;
while(r-l>1e-)//二分法
{
mid=(l+r)/;
if(F(mid))
l=mid;
else
r=mid;
}
printf("%.4lf\n",r);
}
int main()
{
int N,T;
scanf("%d",&N);
while(N--)
{
scanf("%d%d",&n,&k);
man =;
for(i=;i<n;i++){
scanf("%d",&T);
L[i] = PI*T*T; if(man < L[i]) man = L[i];//找出最大的蛋糕面积
}
qw();
}
return ;
}