题目:
http://acm.hdu.edu.cn/showproblem.php?pid=3622
题意:
一个游戏有n轮,每轮给出两个点的坐标,表示以这两个点之中的一个为圆心画一个圆,半径自定,但要求n轮后画出的n个圆之间不能相交,求半径最小的那个圆的半径最大是多少
思路:
首先最大化最小值,这是二分的典型套路,我们二分半径,然后对于不同组的两点,如果他们之间距离小于2倍的枚举值,那么就是两者只能存在一个,连边建图,用2-sat判断当前枚举值是否可行
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
const int N = 210;
const double eps = 1e-8;
struct edge
{
int to, next;
} g[N*N*2];
struct node
{
double x, y;
} arr[N];
int cnt, head[N], cnt1, head1[N];
int dfn[N], low[N], scc[N], st[N], top, num, idx;
bool vis[N];
int n, m;
void add_edge(int v, int u)
{
g[cnt].to = u, g[cnt].next = head[v], head[v] = cnt++;
}
void init()
{
memset(head, -1, sizeof head);
memset(dfn, -1, sizeof dfn);
memset(vis, 0, sizeof vis);
top = num = idx = cnt = 0;
}
void tarjan(int v)
{
dfn[v] = low[v] = ++idx;
vis[v] = true, st[top++] = v;
int u;
for(int i = head[v]; i != -1; i = g[i].next)
{
u = g[i].to;
if(dfn[u] == -1)
{
tarjan(u);
low[v] = min(low[v], low[u]);
}
else if(vis[u])low[v] = min(low[v], dfn[u]);
}
if(dfn[v] == low[v])
{
num++;
do
{
u = st[--top];
vis[u] = false;
scc[u] = num;
}
while(u != v);
}
}
double dis(node a, node b)
{
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
bool work(double mid)
{
init();
for(int i = 0; i < 2*n; i++)
for(int j = i + 1; j < 2*n; j++)
if((i^1) != j)
{
double l = dis(arr[i], arr[j]);
if(l < 2*mid) add_edge(i, j^1), add_edge(j, i^1);
}
for(int i = 0; i < 2*n; i++)
if(dfn[i] == -1) tarjan(i);
for(int i = 0; i < 2*n; i += 2)
if(scc[i] == scc[i+1]) return false;
return true;
}
int main()
{
while(~ scanf("%d", &n))
{
for(int i = 0; i < 2*n; i++) scanf("%lf%lf", &arr[i].x, &arr[i].y);
double l = 0, r = 40000, res;
while(l <= r)
{
double mid = (l + r) / 2;
if(work(mid)) l = mid + eps, res = mid;
else r = mid - eps;
}
printf("%.2f\n", res);
}
return 0;
}