题目大意:有N对点,给定这N对点的坐标,现在要求找出一个最大的半径R,使得可以从每对点中选择一个点,并且这N个点以自己为圆心,半径为R的圆两两不相交。
2-SAT问题解法:对于每一对点,我们且称之为“兄弟点”;对于这2*N个点,如果两个点之间“矛盾”,对于本题即两个圆相交,则连一条边。对这个图求强连通分量,然后看是否有某对点属于同一个强连通分量。如果N对点每一对都属于不同的强连通分量,满足。否则不满足。然后二分半径即可。
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define L(i) i<<1
#define R(i) i<<1|1
#define INF 0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-9
#define maxn 40100
#define MOD 1000000007
struct Edge
{
int to,next;
} edge[maxn<<1];
struct node
{
double x,y;
} a[210];
int n,m,ans;
int tot,head[maxn],scc;
int dfn[maxn],low[maxn],time;
int sta[maxn],top,instack[maxn];
int belong[maxn];
void init()
{
tot = 0;
memset(head,-1,sizeof(head));
}
void add_edge(int u,int v)
{
edge[tot].to = v;
edge[tot].next = head[u];
head[u] = tot++;
}
void tarjan(int u)
{
dfn[u] = low[u] = ++time;
sta[++top] = u;
instack[u] = 1;
for(int i = head[u]; i != -1; i = edge[i].next)
{
int v = edge[i].to;
if(!dfn[v])
{
tarjan(v);
low[u] = min(low[u],low[v]);
}
else if(instack[v])
low[u] = min(low[u],dfn[v]);
}
if(dfn[u] == low[u])
{
scc++;
while(1)
{
int v = sta[top--];
instack[v] = 0;
belong[v] = scc;
if(v == u)
break;
}
}
}
int solve()
{
top = time = scc = 0;
memset(dfn,0,sizeof(dfn));
memset(belong,0,sizeof(belong));
memset(instack,0,sizeof(instack));
for(int i = 0; i < 2*n; i++)
if(!dfn[i])
tarjan(i);
for(int i = 0; i < 2*n; i+=2)
if(belong[i] == belong[i+1])
return 0;
return 1;
}
double dis(int i,int j)
{
return sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x) + (a[i].y-a[j].y)*(a[i].y-a[j].y));
}
int main()
{
int t;
while(scanf("%d",&n) != EOF)
{
for(int i = 0; i < 2*n; i+=2)
scanf("%lf%lf%lf%lf",&a[i].x,&a[i].y,&a[i^1].x,&a[i^1].y);
double l = 0,r = 40000.0;
while(r - l > 1e-5)
{
double mid = (r + l) / 2;
init();
for(int i = 0; i < 2*n; i+=2)
for(int j = i + 2; j <= 2*n; j++)
if(dis(i,j) < 2*mid)
{
add_edge(i,j^1);
add_edge(j,i^1);
}
for(int i = 1; i < 2*n; i+=2)
for(int j = i+1; j < 2*n; j++)
if(dis(i,j) < 2*mid)
{
add_edge(i,j^1);
add_edge(j,i^1);
}
if(solve())
l = mid;
else
r = mid;
}
printf("%.2f\n",l);
}
return 0;
}