poj3122Pie

http://poj.org/problem?id=3122

View Code
 1 #include <iostream>

 2 #include<cstdio>

 3 #include<cstring>

 4 #include<stdlib.h>

 5 #include<cmath>

 6 #define eps 1e-8

 7 #define pi 3.14159265359//精度高一点 6位错了一次

 8 using namespace std;

 9 int main()

10 {

11     int i,j,n,f,t;

12     double r[10005];

13     cin>>t;

14     while(t--)

15     {

16         cin>>n>>f;

17         double low=0.0,high = 0.0;

18         for(i = 1; i <= n ; i++)

19         {

20             cin>>r[i];

21             if((r[i]*r[i])>high)

22                 high = r[i]*r[i];

23         }

24         double mid = (low+high)/2;

25         while(low+eps<high)

26         {

27             int k = 0 ;

28             for(i = 1 ; i <= n ; i++)

29             {

30                 k+=(int)((r[i]*r[i])/mid);

31             }

32             if(k>=(f+1))

33                 low = mid ;

34             else

35                 high = mid;

36             mid = (low+high)/2;

37         }

38         printf("%.4lf\n",pi*mid+eps);

39     }

40     return 0;

41 }

 

你可能感兴趣的:(poj)