标签:
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6158 Accepted Submission(s):
2343
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<cmath> 5 #define PI acos(-1.0)//PI的精度最好大点 6 using namespace std; 7 8 double L[50000] , man; 9 int n,k,i; 10 11 bool F(double x) 12 { 13 int sum=0; 14 for(i=0;i<n;i++) 15 sum+=(int)(L[i]/x);//sum的作用是记录当要求的面积为x时,最多能分多少整块 16 return sum>=(k+1);//如果能分的比要求的多就返回真 17 } 18 void qw() 19 { 20 double l=0,r=man,mid; 21 while(r-l>1e-7)//二分法 22 { 23 mid=(l+r)/2; 24 if(F(mid)) 25 l=mid; 26 else 27 r=mid; 28 } 29 printf("%.4lf\n",r); 30 } 31 int main() 32 { 33 int N,T; 34 scanf("%d",&N); 35 while(N--) 36 { 37 scanf("%d%d",&n,&k); 38 man =0; 39 for(i=0;i<n;i++){ 40 scanf("%d",&T); 41 L[i] = PI*T*T; 42 43 if(man < L[i]) man = L[i];//找出最大的蛋糕面积 44 } 45 qw(); 46 } 47 return 0; 48 }
标签:
原文地址:http://www.cnblogs.com/Eric-keke/p/4690621.html