标签:
题意:给出n个圆,分给n+1个人,求每个人最多能够得到多大面积的圆
二分每个人得到的圆的面积
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<stack> 6 #include<vector> 7 #include<map> 8 #include<set> 9 #include<queue> 10 #include<algorithm> 11 using namespace std; 12 13 typedef long long LL; 14 const int INF = (1<<30)-1; 15 const int mod=1000000007; 16 const int maxn=1000005; 17 const double pi = 3.14159265359; 18 19 double a[maxn]; 20 int n,f; 21 22 int ok(double x){ 23 int ans = 0; 24 for(int i = 1;i <= n;i++){ 25 ans += (int) (a[i] / x); 26 } 27 return ans >= f+1; 28 } 29 30 int main(){ 31 int T; 32 scanf("%d",&T); 33 while(T--){ 34 scanf("%d %d",&n,&f); 35 double lb,ub,mid; 36 ub = -1; 37 for(int i =1;i <= n;i++){ 38 scanf("%lf",&a[i]); 39 a[i] = a[i] * a[i]; 40 ub = max(ub,a[i]); 41 } 42 43 lb = 0.000; 44 for(int i = 0;i<=100;i++){ 45 mid = (lb + ub) / 2; 46 if(ok(mid)) lb = mid; 47 else ub = mid; 48 // printf("lb = %lf ub = %lf mid = %lf\n",lb,ub,mid); 49 } 50 printf("%.4lf\n",lb * pi); 51 } 52 return 0; 53 }
标签:
原文地址:http://www.cnblogs.com/wuyuewoniu/p/4626668.html