给n组点,每组2个,在每组中选取一个作为圆心,做一些圆,要求圆与圆不能相交,问这些圆中的最小半径的最大值为多少
假设所有圆均为等半径,二分答案,2-SAT判断是否有可行解
#include <cstring>
#include <cstdio>
#include <cmath>
bool canPut(int x1,int y1,int x2,int y2,double r) {
if ((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)>=4*r*r) return true;
return false;
}
struct Rou{
int x1,y1,x2,y2;
void read() {
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
}
};
Rou d[100];
int n;
struct Node {
int fe,dfn,low,scc,num;
bool instack;
};
struct Edge {
int t,ne;
};
Node a[210];
Edge b[40010];
int stk[210];
int m,idx,p;
void putedge(int x,int y) {
//printf("--%d %d\n",x,y);
b[p].t=y;
b[p].ne=a[x].fe;
a[x].fe=p;
p++;
}
inline int min(int x,int y) {
return x<y?x:y;
}
void tarjan(int i) {
a[i].dfn=a[i].low=idx++;
a[i].instack=true;
stk[p++]=i;
for (int j=a[i].fe;j;j=b[j].ne) {
if (a[b[j].t].dfn==0) {
tarjan(b[j].t);
a[i].low=min(a[i].low,a[b[j].t].low);
} else if (a[b[j].t].instack) {
a[i].low=min(a[i].low,a[b[j].t].dfn);
}
}
if (a[i].low==a[i].dfn) {
p--;
while (stk[p]!=i) {
a[stk[p]].instack=false;
a[stk[p]].scc=i;
a[i].num++;
p--;
}
a[i].instack=false;
a[i].scc=i;
a[i].num++;
}
}
bool can(double t) {
int i,j;
memset(a,0,sizeof(a));
p=1;
for (i=0;i<n;i++) {
for (j=i+1;j<n;j++) {
if (!canPut(d[i].x1,d[i].y1,d[j].x1,d[j].y1,t)) {
putedge(i*2,j*2+1);
putedge(j*2,i*2+1);
}
if (!canPut(d[i].x1,d[i].y1,d[j].x2,d[j].y2,t)) {
putedge(i*2,j*2);
putedge(j*2+1,i*2+1);
}
if (!canPut(d[i].x2,d[i].y2,d[j].x1,d[j].y1,t)) {
putedge(i*2+1,j*2+1);
putedge(j*2,i*2);
}
if (!canPut(d[i].x2,d[i].y2,d[j].x2,d[j].y2,t)) {
putedge(i*2+1,j*2);
putedge(j*2+1,i*2);
}
}
}
idx=1;
p=1;
for (i=n+n-1;i>=0;i--) {
if (a[i].dfn==0) tarjan(i);
}
for (i=0;i<n;i++) {
//printf("%d %d\n",a[i*2].scc,a[i*2+1].scc);
if (a[i*2].scc==a[i*2+1].scc) return false;
}
return true;
}
int main() {
int i;
while (scanf("%d",&n)!=EOF) {
for (i=0;i<n;i++) d[i].read();
double l=0,r=10000;
while (r-l>0.000001) {
double t=(r+l)/2;
if (can(t)) l=t;
else r=t;
}
printf("%.2lf\n",l);
}
return 0;
}