题目描述
Pie
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 9410 | Accepted: 3391 | Special Judge |
Description

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
解题报告
切蛋糕,求最大蛋糕的体积。
要求蛋糕需要连续,也就是不能求和平均。。。
数据精度要求偏高。WA了数次竟然是精度没有取够。
代码
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cmath>
#include <math.h>
#define PI 3.1415926535897932
using namespace std;
bool jud(int *rad,int &n,int &fri,double &mid){
int temp=fri+1;
for(int i=1;i<=n;i++){
temp-=(int)((rad[i]*rad[i])/mid);
}
return temp<=0?true:false;
}
double solve(int *rad,int &n,int &fri){
double mid,r=100000000,l=0;
while(fabs(r-l)>1e-6)
{
mid=(r+l)/2;
if(jud(&rad[0],n,fri,mid))
l=mid;
else
r=mid;
}
return l;
}
int main()
{
int raii[10500];
int test;
int fri,n;
scanf("%d",&test);
for(;test>0;test--)
{
scanf("%d%d",&n,&fri);
for(int i=1;i<=n;i++)
scanf("%d",&raii[i]);
double res=solve(&raii[0],n,fri);
printf("%.4f\n",res*PI);
}
return 0;
}