Qiuqiqiu  
不管道路多么崎岖坎坷,我永远不停下追逐梦想的脚步!

http://acm.hdu.edu.cn/showproblem.php?pid=1969

二分法

我的代码
 1 #include <stdio.h>
2 #include <math.h>
3 const double eps=1e-6;
4 const double pi=acos(-1.0);
5 const int N=10010;
6 double a[N];
7 int n,f;
8 int ok(double m)
9 {
10 int i,cnt=0;
11 for (i=1;i<=n;i++)
12 cnt+=(int)(a[i]/m);
13 return cnt>f;
14 }
15 int main()
16 {
17 int T,i;
18 double s,r,l,m;
19 scanf("%d",&T);
20 while (T--)
21 {
22 s=0;
23 scanf("%d%d",&n,&f);
24 for (i=1;i<=n;i++)
25 {
26 scanf("%lf",&r);
27 a[i]=r*r*pi;
28 s+=a[i];
29 }
30 l=0; r=s;
31 while (r-l>eps)
32 {
33 m=(l+r)/2;
34 if (!ok(m)) r=m;
35 else l=m;
36 }
37 printf("%.4lf\n",l);
38 }
39 return 0;
40 }

 

posted on 2011-12-10 17:04  Qiuqiqiu  阅读(166)  评论(0编辑  收藏  举报