HDU 5046 Airport (repeated DLX coverage)
Problem DescriptionThe country of jiuye composed by N cites. each city can be viewed as a point in a two-dimen1_plane with integer coordinates (x, y ). the distance between city I and city j is defined by dij = | xi-xj | + | yi-yj |. jiuye want to setup airport in K cities among N cities. so he need your help to choose these K cities, to minimize the maximum distance to the nearest airport of each city. that is, if we define di (1 ≤ I ≤ N) as the distance from city I to the nearest city with airport. your aim is to minimize the value max {di | 1 ≤ I ≤ N }. you just output the minimum.
InputThe first line of the input is T (1 ≤ T ≤ 100), which stands for the number of test cases you need to solve.
The first line of each case contains two integers N, K (1 ≤ N ≤ 60, 1 ≤ K ≤ N), as mentioned above.
The next N lines, each lines contains two integer xi and yi (-109 ≤ xi, yi ≤ 109), denote the coordinates of city I.
OutputFor each test case, print a line "Case # t:" (without quotes, t means the index of the test case) at the beginning. Then a single integer means the minimum.
Sample Input
23 20 04 05 14 20 31 03 08 9
Sample Output
Case #1: 2Case #2: 4
Question: to build up to k airports in n cities, ask the maximum distance between cities. DLX practices: similar to HDU 2295 Radar (DLX can be repeatedly covered). Our practice is to save the distance between n cities. The result is a binary result, calculate the coverage degree for the DLX that meets the conditions and the maximum distance and minimum value. This question is divided into two parts: 0 ~ INF can also be resolved. I just want to hurry up.
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Using namespace std; # define REPF (I, a, B) for (int I = a; I <= B; ++ I) # define REP (I, n) for (int I = 0; I <n; ++ I) # define CLEAR (a, x) memset (a, x, sizeof a) typedef long LL; typedef pair
Pil; const int maxn = 60 + 5; const int maxnnode = maxn * maxn; const int mod = 1000000007; int K; struct DLX {int n, m, size; int U [maxnnode], D [maxnnode], L [maxnnode], R [maxnnode], Row [maxnnode], Col [maxnnode]; int H [maxn], S [maxn]; // H [I] location, S [I] Count int ansd; void init (int a, int B) {n = a; m = B; REPF (I, 0, m) {S [I] = 0; U [I] = D [I] = I; L [I] = I-1; R [I] = I + 1;} R [m] = 0; L [0] = m; size = m; REPF (I, 1, n) H [I] =-1;} void link (int r, int c) {++ S [Col [++ size] = c]; Row [size] = r; D [size] = D [c]; U [D [c] = size; U [size] = c; D [c] = size; if (H [r] <0) H [r] = L [size] = R [size] = size; else {R [size] = R [H [r]; L [R [H [r] = size; L [size] = H [r]; R [H [r] = size ;}} void remove (int c) {for (int I = D [c]; I! = C; I = D [I]) L [R [I] = L [I], R [L [I] = R [I];} void resume (int c) {for (int I = U [c]; I! = C; I = U [I]) L [R [I] = R [L [I] = I;} bool v [maxn]; int f () {int ret = 0; for (int c = R [0]; c! = 0; c = R [c]) v [c] = true; for (int c = R [0]; c! = 0; c = R [c]) if (v [c]) {ret ++; v [c] = false; for (int I = D [c]; i! = C; I = D [I]) for (int j = R [I]; j! = I; j = R [j]) v [Col [j] = false;} return ret;} bool Dance (int d) {if (d + f ()> k) return false; if (R [0] = 0) return d <= K; int c = R [0]; for (int I = R [0]; i! = 0; I = R [I]) if (S [I] <S [c]) c = I; for (int I = D [c]; I! = C; I = D [I]) {remove (I); for (int j = R [I]; j! = I; j = R [j]) remove (j); if (Dance (d + 1) return true; for (int j = L [I]; j! = I; j = L [j]) resume (j); resume (I) ;}return false ;}; struct point {LL x, y ;} X [maxn]; LL d [maxn] [maxn]; LL dd [maxn * maxn]; dlx l; int t, n, cnt; int cas = 1; LL dis (point a, point B) {return abs (. x-b.x) + abs (. y-b.y);} void solve () {int l = 0, r = cnt-1; // int ans; while (l <= r) {int mid = (l + r)> 1; L. init (n, n); REPF (I, 1, n) {REPF (j, 1, n) if (d [I] [j] <= dd [mid]) l. link (I, j);} if (L. dance (0) r = mid-1; else l = mid + 1;} printf ("Case # % d: % I64d \ n", cas ++, dd [l]);} int main () {LL x, y; scanf ("% d", & t); while (t --) {scanf ("% d", & n, & K); REPF (I, 1, n) {scanf ("% I64d % I64d", & x, & y); X [I]. x = x; X [I]. y = y;} cnt = 0; REPF (I, 1, n) {REPF (j, 1, n) {d [I] [j] = dis (X [I], X [j]); dd [cnt ++] = d [I] [j];} sort (dd, dd + cnt); solve ();} return 0 ;}