uva 12097 - Pie

简单题,二分就行;

 1 #include<cstdio>
 2 #include<cmath>
 3 #define pi acos(-1.0)
 4 #define eps 0.000001
 5 #define maxn 10009
 6 using namespace std;
 7 double area[maxn];
 8 
 9 int main()
10 {
11     int t,n,f,ri;
12     double r=-1;
13     scanf("%d",&t);
14     while(t--)
15     {
16         scanf("%d%d",&n,&f);
17         f=f+1;
18         for(int i=0;i<n;i++)
19         {
20             scanf("%d",&ri);
21             area[i]=ri*ri*pi;
22             if(area[i]>r)r=area[i];
23         }
24         double l=0.0;
25         while(r-l>eps)
26         {
27             double mid=(r+l)/2;
28             int cnt=0;
29             for(int i=0;i<n;i++)
30                 cnt+=floor(area[i]/mid);
31             if(cnt>=f)l=mid;
32             else r=mid;
33         }
34         printf("%.4lf\n",l);
35     }
36     return 0;
37 }
View Code

 

posted @ 2013-10-26 10:57  Yours1103  阅读(171)  评论(0编辑  收藏  举报