hdu 5046 Airport (重复覆盖)
来源:互联网 发布:安徽网络电视台看不了 编辑:程序博客网 时间:2024/06/05 21:11
Airport
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1481 Accepted Submission(s): 469
Problem Description
The country of jiuye composed by N cites. Each city can be viewed as a point in a two- dimensional 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.
Input
The 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.
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.
Output
For 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
Source
2014 ACM/ICPC Asia Regional Shanghai Online
二分 + 重复覆盖
/*======================================================# Author: whai# Last modified: 2015-10-09 11:30# Filename: hdu5046.cpp======================================================*/#include <iostream>#include <cstdio>#include <vector>#include <algorithm>#include <cstring>#include <string>#include <cmath>#include <set>#include <map>using namespace std;#define LL __int64#define PB push_back#define P pair<int, int>#define X first#define Y secondconst int MAXM = 65;const int MAXN = 65;const int N = MAXN * MAXM;const int INF = 0x3f3f3f3f;struct DLX { int n, m, size; int U[N], D[N], R[N], L[N], row[N], col[N]; int H[MAXN], S[MAXM]; int ans[MAXN], ans_cnt; void init(int _n, int _m) { ans_cnt = INF; n = _n; m = _m; for (int i = 0; i <= m; i++) { S[i] = 0; U[i] = D[i] = i; L[i] = i - 1; R[i] = i + 1; } R[m] = 0; L[0] = m; size = m; for (int i = 1; i <= n; i++)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[MAXM]; 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; }//注意这些可以加入剪枝优化的 /*void dance(int d) { if (d + f() >= ans_cnt) return; if (R[0] == 0) { if (d < ans_cnt) ans_cnt = d; return ; } 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); //ans[d] = row[i]; for (int j = R[i]; j != i; j = R[j]) remove(j); dance(d + 1); for (int j = L[i]; j != i; j = L[j]) resume(j); resume(i); } }*/bool dance(int d, int limit) {if (d + f() > limit) return false; if (R[0] == 0) return d <= limit; 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, limit)) return true; for (int j = L[i]; j != i; j = L[j]) resume(j); resume(i); }return false; }} dlx;P a[N];LL _abs(int x) { if(x < 0) return -x; return x;}LL dis(P a, P b) { return _abs(a.X - b.X) + _abs(a.Y - b.Y);}bool ok(LL d, int n, int k) { dlx.init(n, n); for(int i = 0; i < n; ++i) { for(int j = 0; j < n; ++j) { if(dis(a[i], a[j]) <= d) { dlx.link(i + 1, j + 1); } } } return dlx.dance(0, k);}void gao(int n, int k) { LL L = 0, R = 4 * 1e9, ans = 4 * 1e9; while(L < R) { LL mid = (L + R) >> 1; if(!ok(mid, n, k)) { L = mid + 1; } else { ans = min(ans, mid); R = mid; } } if(ok(L, n, k)) ans = min(ans, L); if(ok(R, n, k)) ans = min(ans, R); printf("%I64d\n", ans);}int main() { int T; int cas = 0; scanf("%d", &T); while(T--) { int n, k; scanf("%d%d", &n, &k); for(int i = 0; i < n; ++i) { scanf("%d%d", &a[i].X, &a[i].Y); } printf("Case #%d: ", ++cas); gao(n, k); } return 0;}
0 0
- hdu 5046 Airport (重复覆盖)
- 【HDU】5046 Airport 二分+重复覆盖
- HDU 5046 Airport ( Dancing Links 重复覆盖 )
- HDU 5046 Airport(DLX重复覆盖)
- hdu 5046 airport DLX可重复覆盖
- HDU 5046 Airport【DLX重复覆盖】
- HDU-5046 Airport(二分+DLX重复覆盖)
- hdu 5046 Airport(Dancing Links重复覆盖)
- HDU 5046 Airport (DLX可重复覆盖+二分)
- HDU 5046 Airport(二分+DLX重复覆盖)
- HDU 5046 Airport DLX多重覆盖
- DLX重复覆盖 hdu5046 Airport
- hdu 5046 重复覆盖
- HDU 5046 Airport DLX
- HDU 5046 Airport
- hdu 5046 Airport
- HDU 5046 Airport
- HDU 5046 Airport
- HDU 5122 K.Bro Sorting
- (学习笔记)投影与三维视觉——本征矩阵和基础矩阵
- xcode7/ios9中 低版本app运行时,屏幕上下出现黑边的问题
- 操作系统的疑问--------有关磁盘与文件系统及系统启动的疑问????
- 深入了解canvas
- hdu 5046 Airport (重复覆盖)
- Device Tree(三):代码分析
- iOS 手机通讯录
- 去掉android应用中的系统标题栏
- 软件工程
- __lll_mutex_lock_wait的错误原因
- Mac搭建Hexo指南
- apache反向代理
- 浅谈-tomcat中的项目之间的访问