hdu 3264 Open-air shopping malls 计算几何
简单二分枚举求圆的面积交
View Code
#include<cstdio>
#include<cmath>
const double eps = 1e-8;
const double pi = acos(-1.0);
struct Point{
double x,y;
}p[1000];
struct circle{
Point pp;
double r;
}cir[30];
double area[30];
int n;
double cir_area_inst(Point c1, double r1, Point c2, double r2) { // 两圆面积交
double a1, a2, d, ret;
d = sqrt((c1.x-c2.x)*(c1.x-c2.x)+(c1.y-c2.y)*(c1.y-c2.y));
if ( d > r1 + r2 - eps )
return 0;
if ( d < r2 - r1 + eps )
return pi*r1*r1;
if ( d < r1 - r2 + eps )
return pi*r2*r2;
a1 = acos((r1*r1+d*d-r2*r2)/2/r1/d);
a2 = acos((r2*r2+d*d-r1*r1)/2/r2/d);
ret = (a1-0.5*sin(2*a1))*r1*r1 + (a2-0.5*sin(2*a2))*r2*r2;
return ret;
}
bool judge(Point p,double r){
int i,j;
for(i=1;i<=n;i++){
double Are=cir_area_inst(p,r,cir[i].pp,cir[i].r);
if(Are<area[i]) return false;
}
return true;
}
int main(){
int t,i,j;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%lf%lf%lf",&cir[i].pp.x,&cir[i].pp.y,&cir[i].r);
area[i]=pi*cir[i].r*cir[i].r/2;
}
Point a;
double rans=200000;
for(i=1;i<=n;i++){
a=cir[i].pp;
double l=0,r=200000,mid;
while(fabs(l-r)>eps){
mid=(l+r)/2;
if(judge(a,mid)){
r=mid;
if(mid<rans)
rans=mid;
}
else l=mid;
}
}
printf("%.4lf\n",rans);
}
return 0;
}