hdu3264Open-air shopping malls(二分)

时间:2021-10-22 00:15:20

链接

枚举伞的圆心,最多只有20个,因为必须与某个现有的圆心重合。

然后再二分半径就可以了。

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 25
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct point
{
double x,y;
double r,s;
point(double x=,double y=):x(x),y(y) {}
} p[N];
int n;
typedef point pointt;
pointt operator -(point a,point b)
{
return point(a.x-b.x,a.y-b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
}
double circle_area(point a,point b)
{
double s,d,t,t1;
d=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
if(d>=a.r+b.r) s=;
else if(d<=fabs(a.r-b.r)) s=min(acos(-1.0)*a.r*a.r,acos(-1.0)*b.r*b.r);
else
{
t=(a.r*a.r+d*d-b.r*b.r)/2.0/d;
t1=sqrt(a.r*a.r-t*t);
s=-d*t1+a.r*a.r*acos(t/a.r)+b.r*b.r*acos((d-t)/b.r);
}
return s;
}
int cal(double mid,point pp)
{
int i;
double sum;
pp.r = mid;
for(i = ; i <= n ; i++)
{
sum = circle_area(pp,p[i]);
if(dcmp(sum-p[i].s/)<) return ;
}
//cout<<mid<<" "<<pp.x<<" "<<pp.y<<" "<<pp.r<<endl;
return ;
}
double solve(point pp)
{
double rig = ,lef = ,mid;
while(rig-lef>eps)
{
mid = (rig+lef)/;
if(cal(mid,pp))
rig = mid;
else lef = mid;
}
return rig;
}
int main()
{
int t,i;
cin>>t;
while(t--)
{
scanf("%d",&n);
for(i = ; i <= n ; i++)
{
scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].r);
p[i].s = pi*p[i].r*p[i].r;
}
double ans = INF;
for(i = ; i <= n ; i++)
{
ans = min(ans,solve(p[i]));
}
printf("%.4f\n",ans);
}
return ;
}