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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
| #include<bits/stdc++.h> using namespace std; #define int long long inline int read(){int x=0,f=1;char ch=getchar(); while(ch<'0'|| ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;} #define Z(x) (x)*(x) #define pb push_back
#define N 200010
#define eps 1e-4 double H, W, X[N], Y[N]; struct Point { double x, y; Point operator - (const Point &A) const { Point B; B.x=x-A.x; B.y=y-A.y; return B; } double operator ^ (const Point &A) const { return x * A.y - y * A.x; } bool check() {
if(x < 0 || x > W) return false; if(y < 0 || y > H) return false; return true; } }; namespace Cross { bool Line_cross(Point p1, Point p2, Point p3, Point p4) { double a1 = (p1 - p2) ^ (p3 - p2); double a2 = (p1 - p2) ^ (p4 - p2); if(a1 * a2 >= 0) return false; return true; } bool cross(Point p1, Point p2, Point p3, Point p4) {
bool t1 = Line_cross(p1, p2, p3, p4); bool t2 = Line_cross(p3, p4, p1, p2); return t1 && t2; } } struct node { Point a[3]; void make_node(int i, int j, double k) { a[0] = {X[i], Y[i]}; if(j == 0 || j == 3) a[1] = {X[i], Y[i] + k}; if(j == 3 || j == 1) a[2] = {X[i] + k, Y[i]}; if(j == 1 || j == 2) a[1] = {X[i], Y[i] - k}; if(j == 2 || j == 0) a[2] = {X[i] - k, Y[i]}; } bool check() { if(a[0].check() == false) return false; if(a[1].check() == false) return false; if(a[2].check() == false) return false; return true; } void print() { printf("%lf %lf\n", a[0].x, a[0].y); printf("%lf %lf\n", a[1].x, a[1].y); printf("%lf %lf\n", a[2].x, a[2].y); printf(">> %lld\n", check()); } bool operator ^(const node &A) const {
int f0, f1, g0, g1; for(f0 = 0; f0 <= 2; ++f0) for(f1 = f0+1; f1 <= 2; ++f1) for(g0 = 0; g0 <= 2; ++g0) for(g1 = g0+1; g1<=2; ++g1) { if(Cross::cross(a[f0], a[f1], A.a[g0], A.a[g1])) return true; } return false; } }p[N]; int n, m, i, j, k, T; namespace Graph { int make_node(int i, int j) { return j * n + i; } struct two_sat { int dfn[N], low[N], vis[N], col[N], tot, i; vector<int>G[N]; stack<int>z; void clear() { tot = 0; while(!z.empty()) z.pop(); memset(dfn, 0, sizeof(dfn)); memset(low, 0, sizeof(low)); memset(vis, 0, sizeof(vis)); memset(col, 0, sizeof(col)); for(i=0; i<N; ++i) G[i].clear(); } void add_edge(int u, int v) {
G[u].pb(v); } void dfs(int x) { dfn[x] = low[x] = ++tot; z.push(x); vis[x] = 1; for(auto y : G[x]) { if(vis[y] == -1) continue; if(!vis[y]) dfs(y), low[x] = min(low[x], low[y]); else low[x] = min(low[x], low[y]); }
if(dfn[x] == low[x]) { while(z.top() != x) col[z.top()] = x, vis[z.top()] = -1, z.pop(); col[x] = x; z.pop(); vis[x] = -1; }
} void tarjan() { for(i=1; i<=8*n; ++i) if(!vis[i]) dfs(i);
} int pan(int u, int v) { return col[u] == col[v]; } }Sat; } using namespace Graph; double l, r, mid, ans;
bool check(double k) {
int i, j, x, y, u, v; Sat.clear(); for(i=1; i<=n; ++i) { for(j=0; j<=3; ++j) { u = make_node(i, j); v = make_node(i, j^1); Sat.add_edge(u, v + 4*n); Sat.add_edge(v + 4*n, u ); p[u].make_node(i, j, k);
if(p[u].check() == false) Sat.add_edge(u, u + 4*n);
}
} for(i=1; i<=n; ++i) for(j=i+1; j<=n; ++j) for(x=0; x<=3; ++x) for(y=0; y<=3; ++y) {
u = make_node(i, x); v = make_node(j, y); if(p[u] ^ p[v]) {
Sat.add_edge(u, v + 4*n); Sat.add_edge(v, u + 4*n); } } Sat.tarjan(); for(i=1; i<=n; ++i) for(j=0; j<=3; ++j) { u = make_node(i, j); v = make_node(i, j^1);
if(Sat.pan(u, u + 4*n)) return false;
}
return true; }
signed main() {
freopen("city.in", "r", stdin); freopen("city.out", "w", stdout);
scanf("%lf%lf%lld", &W, &H, &n); for(i=1; i<=n; ++i) { scanf("%lf%lf", &X[i], &Y[i]); } l = 0; r = max(H, W); while(r - l > eps){ mid = (l + r) / 2; if(check(mid)) l = mid, ans = mid; else r = mid; } printf("%.2lf", ans*2); return 0; }
|