Pie
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 15441 | Accepted: 5286 | Special Judge |
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.
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
Source
Northwestern Europe 2006
题意:分蛋糕,给出n个人和m个蛋糕,要求每个人分的蛋糕必须一样多,还得加上自己,就相当于m块蛋糕分给(n+1)个人,有个要求,每个人分的蛋糕必须是从一块蛋糕上的,不能从两块上拼凑,求最多每个人分多少
分析:二分,上界为最大的那块蛋糕的,下界为0,每次看看可以最多分几块,然后在二分,直接用半径的平方二分,减少精度损失和时间的消耗,最后再乘上圆周率
说不太清楚看代码
题意:分蛋糕,给出n个人和m个蛋糕,要求每个人分的蛋糕必须一样多,还得加上自己,就相当于m块蛋糕分给(n+1)个人,有个要求,每个人分的蛋糕必须是从一块蛋糕上的,不能从两块上拼凑,求最多每个人分多少
分析:二分,上界为最大的那块蛋糕的,下界为0,每次看看可以最多分几块,然后在二分,直接用半径的平方二分,减少精度损失和时间的消耗,最后再乘上圆周率
说不太清楚看代码
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
using namespace std;
const double pi=3.141592653589;
const double esp=1e-6;
double r[11234],ans;
int n,m;
void erfen(double l,double rr)
{
int i,j,ct;
if(rr-l>esp) //终止条件
{
double mid=(rr-l)/2+l;
ct=0;
for(i=0;i<n;i++)
{
ct+=(int)(r[i]/mid); //按mid去切,如果mid=5,而蛋糕是12,那就最多切2块
}
//printf("%d\n",ct);
if(ct>=m+1) //符合条件,继续向大分
{
ans=mid;
//printf("%f\n",mid);
erfen(mid,rr);
}
else
{
erfen(l,mid);
}
}
}
int main()
{
int i,j,t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
double max1=-1.00,x;
for(i=0;i<n;i++)
{
scanf("%lf",&x);
r[i]=x*x;
max1=max(max1,r[i]);
}
erfen(0.00,max1);
printf("%.4f\n",ans*pi);
}
return 0;
}