hdu3264 计算几何

Open-air shopping malls

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

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
题意:平面上有n个圆,给定他们各自的半径和圆心。保证任意两个圆不会互相重叠。现在求一个大圆,他的圆心与某个给定圆的圆心重合,且对于每一个给定的圆,大圆至少覆盖该圆面积一半。求出满足要求的大圆的最小半径。
思路:二分半径,枚举圆心。重叠面积求一下,用扇形面积减去三角形面积再求出锲形面积(画图看看吧)。
View Code
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<math.h>
 4 #include<algorithm>
 5 using namespace std;
 6 const int N=50;
 7 const double PI=acos(-1);
 8 const double eps=1e-8;
 9 int n;
10 double F(double x){return x>=0?x:(-x);}
11 double x[N],y[N],r[N];
12 void init()
13 {
14     scanf("%d",&n);
15     for(int i=1;i<=n;i++)
16     scanf("%lf%lf%lf",&x[i],&y[i],&r[i]);
17 }
18 double dis(double x1,double y1,double x2,double y2)
19 {
20     return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
21 }
22 double fusiform(double a,double c,double b)
23 {
24     double angle=acos((a*a+b*b-c*c)/(2*a*b))*2;
25     double s1=a*a*PI*(angle/(2*PI));
26     double s2=a*a*sin(angle)/2;
27     return s1-s2;
28 }
29 bool common(double x1,double y1,double r1,double x2,double y2,double r2)
30 {
31     double d=dis(x1,y1,x2,y2);
32     if(d+eps>=r1+r2)//两圆相离
33     return 0;
34     if(d-eps<=F(r1-r2))//两圆内含
35     {
36         if(r1>r2)
37         return 1;
38         else if (r1*r1*2+eps>=r2*r2)
39         return 1;
40         else
41         return 0;
42     }
43     double value=fusiform(r1,r2,d)+fusiform(r2,r1,d);
44     if(value*2>=r2*r2*PI) return 1;
45     else return 0;
46 }
47 bool check(double ox,double oy,double rr)
48 {
49     for(int i=1;i<=n;i++)
50     if(!common(ox,oy,rr,x[i],y[i],r[i])) return 0;
51     return 1;
52 }
53 double calc(double ox,double oy)
54 {
55     double l,r,mid,value;
56     l=0;r=50000;
57     while(r-l>1e-6)
58     {
59         mid=(l+r)/2;
60         if(check(ox,oy,mid))
61           r=mid;
62         else
63           l=mid;
64     }
65     return l;
66 }
67 void work()
68 {
69     double ans,value;
70     ans=1e+10;
71     for(int i=1;i<=n;i++)
72     {
73         value=calc(x[i],y[i]);
74         if(ans>value) ans=value;
75     }
76     printf("%.4lf\n",ans);
77 }
78 int main()
79 {
80     int t;
81     scanf("%d",&t);
82     while(t--)
83     {
84         init();
85         work();
86     }
87     return 0;
88 }

 

posted @ 2012-09-16 10:52  _sunshine  阅读(663)  评论(0编辑  收藏  举报