Code Render Status : Rendered By HDOJ C Code Render Version 0.01 Beta
#include <stdio.h> #include <math.h> #define PI 3.1415926535897931 double v[10001]; int n,f; int test(double x) { int s=0,i; for (i=0;i<n;i++) s+=(int)(v[i]/x); return s>=f?1:0; } int main() { int cas,i,r; double sum,max; double left,right,mid; scanf("%d",&cas); while (cas--) { scanf("%d%d",&n,&f); f+=1; sum=0; for (i=0;i<n;i++) { scanf("%d",&r); v[i]=(double)PI*r*r; sum+=v[i]; } max=sum/f; left=0.0; right=max; while ((right-left)>1e-6) { mid=(left+right)/2.0; if (test(mid)) left=mid; else right=mid; } printf("%.4lf\n",mid); } return 0; }
本文转自ZH奶酪博客园博客,原文链接:http://www.cnblogs.com/CheeseZH/archive/2012/05/09/2493407.html,如需转载请自行联系原作者