POJ3104_Pie_二分
2014-04-06 00:37
225 查看
题目描述
Pie
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.
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
Sample Output
解题报告
切蛋糕,求最大蛋糕的体积。
要求蛋糕需要连续,也就是不能求和平均。。。
数据精度要求偏高。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;
}
Pie
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 9410 | Accepted: 3391 | Special Judge |
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.
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;
}
相关文章推荐
- poj 3122 Pie(二分)
- POJ 3122 Pie 二分答案
- UVALive 3635-Pie-二分
- hdu-1969-Pie(二分+贪心)
- POJ3104 Drying [二分]
- POJ3104:Drying(二分)
- poj 3122&&hdu1969 Pie(二分)
- hdu_1969_NWERC2006_Pie(二分)
- 【hoj】2651 pie 二分查找
- UVALive 3635 Pie (二分答案)
- HDOJ 1969 Pie(二分)
- Pie(二分)
- 二分搜索--poj3104
- hdu 1969 Pie(二分)
- hdoj 1969 Pie 【二分】
- hdu1969 pie【二分】
- poj 3122 Pie(二分)
- 【二分】hdu 1969 Pie(同木材加工)
- Pie(POJ--3122【二分查找】
- POJ 3122 Pie 二分答案