Open-air shopping malls(二分半径,两元交面积)

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

Open-air shopping malls

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


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

 题意:给出很多的商店,要求一把打伞,伞的圆心要在某个商店中心,伞要覆盖每个圆至少一半的面积,求伞的最小半径

题解: 给的点一共20个,枚举不会超时,枚举每个圆心,然后二分半径找到最小的半径

下面是代码:

其中求两圆交面积的代码是复制的模板

 1 #include <cstdio>
 2 #include <cmath>
 3 #include <algorithm>
 4 using namespace std;
 5 #define eps 1e-6
 6 #define N 25
 7 #define INF 20000
 8 #define pi acos(-1.0)
 9 struct point{
10     double x, y;
11     point(){}
12     point(double _x, double _y) {
13         x = _x, y = _y;
14     }
15 
16     point operator - (point a){
17         return point(x-a.x, y-a.y);
18     }
19 
20     double operator * (point a){
21         return x*a.y - y*a.x;
22     }
23 
24     double len(){
25         return sqrt(x*x+y*y);
26     }
27 };
28 struct circle{
29     point c;
30     double r;
31 };
32 circle cir[N];
33 int n;
34 
35 double dist(point a, point b)
36 {
37     return (a-b).len();
38 }
39 
40 double area_cir_to_cir(circle a,circle b)
41 {
42     double d=dist(a.c,b.c),r1=a.r,r2=b.r,r;
43     if (r1+r2<=d) { return 0.0; }
44     else if (fabs(r1-r2)>=d) {
45         r=min(r1,r2);
46         return pi*r*r;
47     }
48     else {
49         double a1=(r1*r1+d*d-r2*r2)/(2*r1*d);
50         double a2=(r2*r2+d*d-r1*r1)/(2*r2*d);
51         a1=2*acos(a1); a2=2*acos(a2);
52         return (r1*r1*(a1-sin(a1))+r2*r2*(a2-sin(a2)))*0.5;
53     }
54 }
55 
56 bool check(circle a, circle b)
57 {
58     double s1 = area_cir_to_cir(a, b);
59     double s2 = pi*b.r*b.r;
60     return s1*2 > s2-eps;
61 }//函数重载
62 
63 bool check(point o, double r)
64 {
65     circle t;
66     t.c = o, t.r = r;
67     for(int i = 0; i < n; i++)
68         if(!check(t, cir[i]))return false;
69     return true;
70 }
71 
72 double solve(int id)
73 {
74     point o = cir[id].c;
75     double l = 0, r = INF;
76     while(fabs(l-r) > eps)
77     {
78         double m = 0.5*(l+r);
79         if(check(o, m)) r = m;
80         else l = m;
81     }
82     return l;
83 }
84 
85 int main()
86 {
87     int T;
88     scanf("%d", &T);
89     while(T--)
90     {
91         scanf("%d", &n);
92         for(int i = 0; i < n; i++)
93             scanf("%lf %lf %lf", &cir[i].c.x, &cir[i].c.y, &cir[i].r);
94         double ans = INF;
95         for(int i = 0; i < n; i++)
96             ans = min(ans, solve(i));
97         printf("%.4f
", ans);
98     }
99 }
原文地址:https://www.cnblogs.com/shanyr/p/4688354.html