标签:
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9814 Accepted Submission(s):
3568
题意:给出n个蛋糕的半径,还有m+1个人,每个人的馅饼必须是整块的,不能拼接,求最大的。
思路:因为不能拼接,所以直接在最大那块的面积与0之间二分求即可
#include<iostream> #include<cstring> #include<cstdio> #include<queue> #include<cmath> #include<algorithm> using namespace std; #define PI acos(-1.0) int n,f; double area[10005]; bool ok(double a) { int num=0; for(int i=0;i<n;i++) num+=(int)(area[i]/a); if(num>=f+1) return 1; else return 0; } int main() { int r,t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&f); double maxn=0; for(int i=0;i<n;i++) { scanf("%d",&r); area[i]=r*r*PI; if(area[i]>maxn) maxn=area[i]; } double L=0,R=maxn; while(R-L>1e-5) { double M=(R+L)/2; if(ok(M)) L=M; else R=M; } printf("%.4lf\n",L); } return 0; }
标签:
原文地址:http://www.cnblogs.com/jasonlixuetao/p/5823487.html