HDU 5046 Airport DLX多重覆盖
来源:互联网 发布:风云卫星遥感数据网 编辑:程序博客网 时间:2024/06/05 07:59
题目:
http://acm.hdu.edu.cn/showproblem.php?pid=5046
题意:
有n个城市在二维平面上,任意两个城市间的距离为曼哈顿距离,现在在n个城市中选出k个设置机场,要求覆盖全部n个城市,问覆盖半径最小为多少
思路:
跟hdu 3656基本一样,只需要变换一下计算距离的公式即可,注意会爆int
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int X = 10000 + 10, N = 60 + 10, M = 60 + 10, INF = 0x3f3f3f3f;ll x[M], y[M], a[M][M], b[M*M];int cas = 0;struct DLX{ int U[X], D[X], L[X], R[X], row[X], col[X]; int H[N], S[M]; int head, sz, tot, n, m; bool vis[M]; void init(int _n, int _m) { n = _n, m = _m; for(int i = 0; i <= m; i++) L[i] = i-1, R[i] = i+1, U[i] = D[i] = i, S[i] = 0; head = 0, tot = 0, sz = m; L[head] = m, R[m] = head; for(int i = 1; i <= n; i++) H[i] = -1; } void link(int r, int c) { ++S[col[++sz]=c]; row[sz] = r; D[sz] = D[c], U[D[c]] = sz; U[sz] = c, D[c] = sz; if(H[r] < 0) H[r] = L[sz] = R[sz] = sz; else R[sz] = R[H[r]], L[R[H[r]]] = sz, L[sz] = H[r], R[H[r]] = sz; } void del(int x) { for(int i = D[x]; i != x; i = D[i]) R[L[i]] = R[i], L[R[i]] = L[i]; } void recover(int x) { for(int i = U[x]; i != x; i = U[i]) R[L[i]] = L[R[i]] = i; } int fun_f() { memset(vis, 0, sizeof vis); int num = 0; for(int i = R[head]; i != head; i = R[i]) if(! vis[i]) { vis[i] = true; num++; for(int j = D[i]; j != i; j = D[j]) for(int k = R[j]; k != j; k = R[k]) vis[col[k]] = true; } return num; } bool dance(int dep, int k) { if(R[head] == head) { if(dep-1 <= k) return true; else return false; } if(dep-1 + fun_f() > k) return false; int c = R[head]; for(int i = R[head]; i != head; i = R[i]) if(S[i] < S[c]) c = i; for(int i = D[c]; i != c; i = D[i]) { del(i); for(int j = R[i]; j != i; j = R[j]) del(j); if(dance(dep + 1, k)) return true; for(int j = L[i]; j != i; j = L[j]) recover(j); recover(i); } return false; }}dlx;ll dis(ll x1, ll y1, ll x2, ll y2){ return abs(x1-x2) + abs(y1-y2);}int main(){ int t, n, m; scanf("%d", &t); while(t--) { scanf("%d%d", &n, &m); for(int i = 1; i <= n; i++) scanf("%lld%lld", &x[i], &y[i]); int k = 0; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) { a[i][j] = dis(x[i], y[i], x[j], y[j]); b[++k] = a[i][j]; } sort(b + 1, b + 1 + k); k = unique(b + 1, b + 1 + k) - b - 1; int l = 1, r = k, ans; while(l <= r) { int mid = (l + r) / 2; dlx.init(n, n); for(int j = 1; j <= n; j++) for(int k = 1; k <= n; k++) if(a[j][k] <= b[mid]) dlx.link(j, k); if(dlx.dance(1, m)) ans = mid, r = mid - 1; else l = mid + 1; } printf("Case #%d: %lld\n", ++cas, b[ans]); } return 0;}
阅读全文
0 0
- HDU 5046 Airport DLX多重覆盖
- HDU 5046 Airport(DLX重复覆盖)
- hdu 5046 airport DLX可重复覆盖
- HDU 5046 Airport【DLX重复覆盖】
- HDU-5046 Airport(二分+DLX重复覆盖)
- HDU 5046 Airport DLX
- HDU 5046 Airport (DLX可重复覆盖+二分)
- HDU 5046 Airport(二分+DLX重复覆盖)
- HDU 5046 Airport [DLX] [RepeatCover]
- HDU 3656 Fire station DLX多重覆盖
- DLX重复覆盖 hdu5046 Airport
- hdu 5046 Airport (重复覆盖)
- HDU 5046 ( Airport ) DLX模板题,手残again
- HDU 3498 whosyourdaddy(DLX+A*||多重覆盖)
- 【HDU】5046 Airport 二分+重复覆盖
- HDU 5046 Airport ( Dancing Links 重复覆盖 )
- HDU 5046 Airport DLX 2014 ACM/ICPC Asia Regional Shanghai Online
- hdu 4979 A simple math problem. DLX(多重覆盖)+打表
- 未能从程序集.......
- MySQL 数据备份与还原
- 微服务与Docker介绍
- 云盾内容安全8月1日全面升级上线,基于深度学习提供鉴黄、涉政、直播不良场景等10种以上检测服务
- bzoj 4976: 宝石镶嵌 动态规划
- HDU 5046 Airport DLX多重覆盖
- 网络状态判断
- Android模仿软键盘实现软键盘的删除功能(逐个删除EditText的输入元素)
- leetcode[Can Place Flowers]
- 机器学习中的特征空间
- Owl Geeks 【map 模拟】
- android hybird app 踩坑之旅
- 网站统计中的数据收集原理及实现(有说前端如何埋点)
- hdu 5037 Frog 【贪心】