Uva 派 (Pie,NWERC 2006,LA 3635)
依然是一道二分查找
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 using namespace std; 5 6 const double PI=acos(-1.0); 7 int N,F; 8 double r[10001]; 9 10 bool ok(double area) 11 { 12 int sum=0; 13 for(int i=0;i<N;i++) 14 sum+=floor(r[i]/area); 15 return sum>=F+1; 16 } 17 18 int main() 19 { 20 int T; 21 cin>>T; 22 while(T--) 23 { 24 cin>>N>>F; 25 double maxn=-1; 26 for(int i=0;i<N;i++) 27 { 28 int a; 29 cin>>a; 30 r[i]=PI*a*a; 31 maxn=max(maxn,r[i]); 32 } 33 double L=0,R=maxn; 34 while(R-L>1e-4) 35 { 36 double M=(L+R)/2; 37 if(ok(M)) L=M;else R=M; 38 } 39 printf("%.4lf\n",L); 40 } 41 return 0; 42 }