Open-air shopping malls
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2256 Accepted Submission(s): 837
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.
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.
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
主要是求圆相交的面积。。
画图易得。
然后二分半径就好。
1 /************************************************************************* 2 > File Name: code/hdu/3264.cpp 3 > Author: 111qqz 4 > Email: rkz2013@126.com 5 > Created Time: 2015年11月06日 星期五 14时57分47秒 6 ************************************************************************/ 7 8 #include<iostream> 9 #include<iomanip> 10 #include<cstdio> 11 #include<algorithm> 12 #include<cmath> 13 #include<cstring> 14 #include<string> 15 #include<map> 16 #include<set> 17 #include<queue> 18 #include<vector> 19 #include<stack> 20 #include<cctype> 21 #define fst first 22 #define sec second 23 #define lson l,m,rt<<1 24 #define rson m+1,r,rt<<1|1 25 #define ms(a,x) memset(a,x,sizeof(a)) 26 using namespace std; 27 const double eps = 1E-8; 28 const int dx4[4]={1,0,0,-1}; 29 const int dy4[4]={0,-1,1,0}; 30 typedef long long LL; 31 const int inf = 0x3f3f3f3f; 32 const int N=25; 33 const double pi =acos(-1.0); 34 int n; 35 int dblcmp(double d) 36 { 37 return d<-eps?-1:d>eps; 38 } 39 struct point 40 { 41 double x,y; 42 point(){} 43 point(double _x,double _y): 44 x(_x),y(-y){}; 45 void input() 46 { 47 scanf("%lf%lf",&x,&y); 48 } 49 point sub(point p) 50 { 51 return point(x-p.x,y-p.y); 52 } 53 double dot(point p) 54 { 55 return x*p.x+y*p.y; 56 } 57 double det(point p) 58 { 59 return x*p.y-y*p.x; 60 } 61 double distance(point p) 62 { 63 return hypot(x-p.x,y-p.y); 64 } 65 }; 66 67 struct circle 68 { 69 point p; 70 double r; 71 circle(){} 72 circle(point _p,double _r): 73 p(_p),r(_r){}; 74 void input() 75 { 76 p.input(); 77 scanf("%lf",&r); 78 } 79 double area() 80 { 81 return pi*r*r; 82 } 83 84 int relationcircle(circle v) 85 { 86 double d=p.distance(v.p); 87 if (dblcmp(d-r-v.r)>0) return 5; 88 if (dblcmp(d-r-v.r)==0) return 4; 89 double l = fabs(r-v.r); 90 if (dblcmp(d-r-v.r)<0&&dblcmp(d-l)>0) return 3; 91 if (dblcmp(d-l)==0) return 2; 92 if (dblcmp(d-l)<0) return 1; 93 } 94 95 double areacircle(circle v) 96 { 97 int rel = relationcircle(v); 98 if (rel>=4) return 0.0; 99 if (rel<=2) return min(area(),v.area()); 100 double d=p.distance(v.p); 101 double hf=(r+v.r+d)/2.0; 102 double ss=2*sqrt(hf*(hf-r)*(hf-v.r)*(hf-d)); 103 double a1=acos((r*r+d*d-v.r*v.r)/(2.0*r*d)); 104 a1 = a1 *r*r; 105 double a2=acos((v.r*v.r+d*d-r*r)/(2.0*v.r*d)); 106 a2 = a2*v.r*v.r; 107 return a1+a2-ss; 108 } 109 }cir[N]; 110 111 bool judge(double rr) 112 { 113 for ( int i = 1 ,j; i <= n ; i++) 114 { 115 circle tmp = cir[i]; 116 tmp.r = rr; 117 for ( j = 1; j <= n ; j++) 118 { 119 double crossarea = tmp.areacircle(cir[j]); 120 // cout<<"cross_area:"<<crossarea<<endl; 121 if (crossarea<cir[j].area()/2.0) 122 break; 123 } 124 if (j==n+1) return true; 125 126 } 127 return false; 128 129 } 130 int main() 131 { 132 #ifndef ONLINE_JUDGE 133 freopen("in.txt","r",stdin); 134 #endif 135 int T; 136 scanf("%d",&T); 137 while ( T-- ) 138 { 139 scanf("%d",&n); 140 for ( int i = 1 ; i <= n ; i++) cir[i].input(); 141 double l=0,r=1E5; 142 while (dblcmp(r-l)>0) 143 { 144 // cout<<"l:"<<l<<" r:"<<r<<endl; 145 double mid = (l+r)/2.0; 146 if (judge(mid)) 147 r = mid; 148 else l=mid; 149 150 } 151 printf("%.4f ",r); 152 153 } 154 155 156 #ifndef ONLINE_JUDGE 157 #endif 158 fclose(stdin); 159 return 0; 160 }