hdu 3622 Bomb Game

本文从WordPress迁移而来, 查看全部WordPress迁移文章

二分答案 + 2-sat判定

题目:给出n对点,即2n个点,给出每个点的坐标。没对点中只能选一个,以选中的点为圆心画n个圆,这些圆不能出现重叠,在满足条件下,让圆的半径最大

二分枚举圆半径,再用一个二重循环枚举n对点中的每个点,有重叠关系的加必要边,构图完成就判定,基本题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
using namespace std;
#define N 110
#define MAX 10000
#define esp 1e-8
#define cl(xx,yy) memset((xx),(yy),sizeof((xx)))
#define pb push_back

int n,x[2*N],y[2*N];
vector<int>e[2*N];
int dcnt,bcnt,top,dfn[2*N],low[2*N],stack[2*N],belong[2*N];
bool ins[2*N];

inline void add(int u ,int v){
e[u].pb(v);
}

inline double dis(int x1,int y1,int x2,int y2){
return sqrt((double)(x1-x2)*(x1-x2) + (double)(y1-y2)*(y1-y2));
}

void build(double r){
for(int i = 0; i < 2*n; i++)
e[i].clear();
for(int i = 0; i < n; i++)
for(int j = i+1; j < n; j++){
double d;
d = dis(x[i<<1],y[i<<1],x[j<<1],y[j<<1]);
if(d < 2*r){
add(i<<1,j<<1|1); add(j<<1,i<<1|1);
}
d = dis(x[i<<1],y[i<<1],x[j<<1|1],y[j<<1|1]);
if(d < 2*r){
add(i<<1,j<<1); add(j<<1|1,i<<1|1);
}
d = dis(x[i<<1|1],y[i<<1|1],x[j<<1],y[j<<1]);
if(d < 2*r){
add(i<<1|1,j<<1|1); add(j<<1,i<<1);
}
d = dis(x[i<<1|1],y[i<<1|1],x[j<<1|1],y[j<<1|1]);
if(d < 2*r){
add(i<<1|1,j<<1); add(j<<1|1,i<<1);
}
}
}

void tarjan(int u){
dfn[u] = low[u] = ++dcnt;
stack[++top] = u; ins[u] = true;
for(int i = 0; i < e[u].size(); i++){
int v = e[u][i];
if(!dfn[v]){
tarjan(v);
low[u] = min(low[u],low[v]);
}
else if(ins[v])
low[u] = min(low[u],dfn[v]);
}
if(dfn[u] == low[u]){
++bcnt;
while(true){
int x = stack[top--];
ins[x] = false;
belong[x] = bcnt;
if(x == u) break;
}
}
}

bool check(){
dcnt = bcnt = top = 0;
cl(dfn,0);
cl(ins,false);
for(int i = 0; i < 2*n; i++)
if(!dfn[i])
tarjan(i);
for(int i = 0; i < n; i++)
if(belong[i<<1] == belong[i<<1|1])
return false;
return true;
}

int main(){
while(scanf("%d",&n)!=EOF){
for(int i = 0; i < n; i++)
scanf("%d%d%d%d",&x[i<<1],&y[i<<1],&x[i<<1|1],&y[i<<1|1]);
double low = 0;
double high = dis(-MAX,-MAX,MAX,MAX);
double ans = 0;
while(high - low > esp){
double mid = (low + high) / 2;
build(mid);
if(check()){
low = mid; ans = mid;
}
else high = mid;
}
printf("%.2lf\n",ans);
}
return 0;
}