hdu 3264 Open-air shopping malls(圆相交面积+二分)

Open-air shopping malls

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2458    Accepted Submission(s): 906


Problem Description
The city of M is a famous shopping city and its open-air shopping malls are extremely attractive. During the tourist seasons, thousands of people crowded into these shopping malls and enjoy the vary-different shopping.

Unfortunately, the climate has changed little by little and now rainy days seriously affected the operation of open-air shopping malls—it’s obvious that nobody will have a good mood when shopping in the rain. In order to change this situation, the manager of these open-air shopping malls would like to build a giant umbrella to solve this problem.

These shopping malls can be considered as different circles. It is guaranteed that these circles will not intersect with each other and no circles will be contained in another one. The giant umbrella is also a circle. Due to some technical reasons, the center of the umbrella must coincide with the center of a shopping mall. Furthermore, a fine survey shows that for any mall, covering half of its area is enough for people to seek shelter from the rain, so the task is to decide the minimum radius of the giant umbrella so that for every shopping mall, the umbrella can cover at least half area of the mall.
 
Input
The input consists of multiple test cases.
The first line of the input contains one integer T (1<=T<=10), which is the number of test cases.
For each test case, there is one integer N (1<=N<=20) in the first line, representing the number of shopping malls.
The following N lines each contain three integers X,Y,R, representing that the mall has a shape of a circle with radius R and its center is positioned at (X,Y). X and Y are in the range of [-10000,10000] and R is a positive integer less than 2000.
 
Output
For each test case, output one line contains a real number rounded to 4 decimal places, representing the minimum radius of the giant umbrella that meets the demands.
 
Sample Input
1
2
0 0 1
2 0 1
 
Sample Output
2.0822
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  3268 3265 3269 3262 3263 
 
题意:给出一些圆,选择其中一个圆的圆心为圆心,然后画一个大圆,要求大圆最少覆盖每个圆的一半面积。求大圆最小时的半径。
 
枚举每个点,用二分求出需要的圆,更新最小值即可。 
其中用到了圆相交面积,可以参考这题: http://www.cnblogs.com/pshw/p/5711251.html
 
附上代码:
 
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 #define N 25
 7 
 8 const double pi = acos(-1.0);
 9 const double EPS = 1e-8;
10 int n;
11 
12 double max(double a,double b)
13 {
14     return a>b?a:b;
15 }
16 
17 double min(double a,double b)
18 {
19      return a<b?a:b;
20 }
21 
22 struct Round
23 {
24     double x,y;
25     double r;
26 } rr[N],s;
27 
28 double dis(Round a, Round b)  ///两点之间的长度
29 {
30     return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
31 }
32  
33 double solve(Round a, Round b)   ///求两圆相交的面积
34 {
35     double d = dis(a, b);
36     if(d >= a.r + b.r)
37         return 0;
38     else if(d <= fabs(a.r-b.r))
39     {
40         double r = a.r < b.r?a.r : b.r;
41         return pi * r * r;
42     }
43     double ang1 = acos((a.r * a.r + d * d - b.r * b.r) / 2.0 / a.r / d);
44     double ang2 = acos((b.r * b.r + d * d - a.r * a.r) / 2.0 / b.r / d);
45     double ret = ang1 * a.r * a.r + ang2 * b.r * b.r - d * a.r * sin(ang1);
46     return ret;
47 }
48 
49 bool check(Round s)
50 {
51     for(int i=0; i<n; i++)  ///大圆是否覆盖每个圆的一半面积
52     {
53         if(solve(s, rr[i]) * 2 < pi * rr[i].r * rr[i].r)
54             return false;  ///不满足直接返回
55     }
56     return true;
57 }
58 
59 double bin(double l, double r, Round s) ///二分,找出最小圆的半径
60 {
61     double mid;
62     while(fabs(l - r) >= EPS) ///精度划分
63     {
64         mid = (l + r) / 2;
65         s.r = mid;
66         if(check(s)) ///满足返回的说明半径长度足够,有可能可以更短
67             r=mid;
68         else     ///不满足返回的说明半径长度不够,需要更长
69             l=mid+EPS;
70     }
71     return mid;
72 }
73 
74 int main()
75 {
76     int T,i,j;
77     scanf("%d",&T);
78     while(T--)
79     {
80         scanf("%d",&n);
81         for(i=0; i<n; i++)
82             scanf("%lf%lf%lf",&rr[i].x,&rr[i].y,&rr[i].r);
83         double ans = 1e10;
84         for(i=0; i<n; i++)
85         {
86             s.x = rr[i].x;
87             s.y = rr[i].y;
88             double right = 0;
89             for(j=0; j<n; j++)
90             {
91                 right = max(right, dis(s, rr[j]) + rr[j].r); 
92                 ///以当前点为圆心,找出可以覆盖所有的圆面积的最长半径
93             }
94             ans = min(ans, bin(0, right, s)); ///二分搜索,记录最小的圆的半径
95         }
96         printf("%.4f
", ans);
97     }
98     return 0;
99 }
原文地址:https://www.cnblogs.com/pshw/p/5711675.html