分馅饼 Pie

Pie

链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/C

题目:

Problem 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
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

题意:

有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>
using namespace std;
double pi=acos(-1.0); //用反余弦求pi
const int maxn=;
double sum,y;
int n,a[maxn],f;
double b[maxn];
int xz(double m)
{
int x=,i;
for(i=;i<n;i++)
{
x+=(int)(b[i]/m);
}
if(x>=f+)
return ;
else return ;
}
22 void slove()
{
double l=0.0,r=y,mid=;
while((r-l)>1e-) //精度问题
{
mid=(l+r)/;
if(xz(mid)) l=mid;
else r=mid;
}
printf("%.4f\n",l);
}
int main()
{
int i,t;
cin>>t;
while(t--)
{
sum=0.0;
cin>>n>>f;
for(i=;i<n;i++)
{
cin>>a[i];
b[i]=a[i]*a[i]*pi;
sum+=b[i];
}
y=sum/(f+);
slove();
}
return ;
}

 
上一篇:tcpdump for android L 5.x with pie support


下一篇:Oracle触发器trigger3利用时间限制用户输入