Open-air shopping malls
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1427 Accepted Submission(s): 500
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.
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.
1 2 0 0 1 2 0 1
2.0822
这个题目不要想当然的认为离当前圆心最远的点就是答案的出现点,只要在那个圆上枚举就可以了,这个想法
#include <iostream> #include <string.h> #include <stdio.h> #include <cmath> using namespace std; #define eps 1e-8 #define pi acos(-1.0) struct point { double x; double y; double r; double area; }po[200]; int n; double global_ans; double map[50][50]; double area(point a,double r1,point b,double r2) { double d=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));//圆心距 if(r1>r2) { double temp=r1; r1=r2; r2=temp; }//r1取小 if(r1+r2<=d) return 0;//相离 else if(r2-r1>=d) return pi*r1*r1;//内含 else { double a1=acos((r1*r1+d*d-r2*r2)/(2.0*r1*d)); double a2=acos((r2*r2+d*d-r1*r1)/(2.0*r2*d)); return (a1*r1*r1+a2*r2*r2-r1*d*sin(a1)); }//相交 } double dis(point &a,point &b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y*b.y)); } double find_ans(int num,double left,double right) { double temp,mid; if(right > global_ans) right=global_ans; int i; while(right - left > eps) { mid=(right+left)/2; for(i=0;i<n;i++) { temp=area(po[num],mid,po[i],po[i].r); if(temp < po[i].area/2) { left=mid;break;} } if(i==n) right=mid; } if(global_ans > (left+right)/2) global_ans=(left+right)/2; return 0; } int main() { int t; int i,j; scanf("%d",&t); double MAX; while(t--) { scanf("%d",&n); MAX=-1; for(i=0;i<n;i++) { scanf("%lf%lf%lf",&po[i].x,&po[i].y,&po[i].r); po[i].area=pi*po[i].r*po[i].r; } if(n==1) { printf("%.4lf\n",po[0].r/sqrt(2.0)); ////////////////////////////////////// continue; } for(i=0;i<n;i++) for(j=i;j<n;j++) map[i][j]=map[j][i]=dis(po[i],po[j]); global_ans=1e8; for(i=0;i<n;i++) find_ans(i,0,1e6); printf("%.4lf\n",global_ans); } return 0; }