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
| #include <bits/stdc++.h> #define x first #define y second #define mp make_pair #define pii pair<int,int> #define MAX_N 20000 #define INF 0x3f3f3f #define mid ((l+r)>>1) using namespace std; template <class T> inline void read(T &x) { x = 0; int c = getchar(), f = 1; for (; !isdigit(c); c = getchar()) if (c == 45) f = -1; for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0'); } int n; pii p[MAX_N+5]; bool mrk[MAX_N+5]; bool chk(int r) { int x1 = INF, y1 = INF, x2 = -INF, y2 = -INF; for (int i = 1; i <= n; i++) if (!mrk[i]) x1 = min(x1, p[i].x), y1 = min(y1, p[i].y), x2 = max(x2, p[i].x), y2 = max(y2, p[i].y); return x2-x1 <= r && y2-y1 <= r; } int del(int sx, int sy, int r) { int ret = 0; for (int i = 1; i <= n; i++) if (!mrk[i]) if (p[i].x >= sx && p[i].x <= sx+r) if (p[i].y >= sy && p[i].y <= sy+r) mrk[i] = true, ret++; return ret; } bool DFS(int stp, int lft, int r) { if (!lft) return true; if (stp > 2) return chk(r); int x1 = INF, y1 = INF, x2 = -INF, y2 = -INF; for (int i = 1; i <= n; i++) if (!mrk[i]) x1 = min(x1, p[i].x), y1 = min(y1, p[i].y), x2 = max(x2, p[i].x), y2 = max(y2, p[i].y); bool bk[MAX_N+5]; memcpy(bk, mrk, sizeof mrk); if (DFS(stp+1, lft-del(x1, y1, r), r)) return true; memcpy(mrk, bk, sizeof bk); if (DFS(stp+1, lft-del(x1, y2-r, r), r)) return true; memcpy(mrk, bk, sizeof bk); if (DFS(stp+1, lft-del(x2-r, y1, r), r)) return true; memcpy(mrk, bk, sizeof bk); if (DFS(stp+1, lft-del(x2-r, y2-r, r), r)) return true; memcpy(mrk, bk, sizeof bk); return false; } int bi_search(int l, int r) { int ret = -1; while (l <= r) { memset(mrk, false, sizeof mrk); if (!DFS(1, n, mid)) l = mid+1; else ret = mid, r = mid-1; } return ret; } int main() { read(n); for (int i = 1; i <= n; i++) read(p[i].x), read(p[i].y); return printf("%d\n", bi_search(1, INF)), 0; }
|