HDU 5046 Airport(DLX反复覆盖)
HDU 5046 Airport
题意:给定一些机场。要求选出K个机场,使得其它机场到其它机场的最大值最小
思路:二分+DLX反复覆盖去推断就可以
代码:
#include <cstdio>
#include <cstring> using namespace std; const int MAXNODE = 4005;
const int MAXM = 65;
const int MAXN = 65;
const int INF = 0x3f3f3f3f; int K; struct DLX { int n, m, size; int U[MAXNODE], D[MAXNODE], R[MAXNODE], L[MAXNODE], row[MAXNODE], col[MAXNODE];
int H[MAXN], S[MAXM];
int ansd, ans[MAXN]; void init(int n, int m) {
this->n = n;
this->m = m;
ansd = INF;
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[MAXNODE]; 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);
ans[d] = row[i];
if (Dance(d + 1)) return true;
for(int j = L[i]; j != i; j = L[j]) resume(j);
resume(i);
}
return false;
}
} gao; typedef long long ll; int T, n; const int N = 65; struct City {
ll x, y;
void read() {
scanf("%I64d%I64d", &x, &y);
}
} c[N]; ll dis(City a, City b) {
ll dx = a.x - b.x; if (dx < 0) dx = -dx;
ll dy = a.y - b.y; if (dy < 0) dy = -dy;
return dx + dy;
} int main() {
int cas = 0;
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &K);
for (int i = 1; i <= n; i++) c[i].read();
ll l = 0, r = 100000000000LL;
while (l < r) {
ll mid = (l + r) / 2;
gao.init(n, n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (dis(c[i], c[j]) <= mid)
gao.Link(i, j);
}
}
if (gao.Dance(0)) r = mid;
else l = mid + 1;
}
printf("Case #%d: %I64d\n", ++cas, l);
}
return 0;
}
HDU 5046 Airport(DLX反复覆盖)的更多相关文章
- HDU 5046 Airport(dlx)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5046 题意:n个城市修建m个机场,使得每个城市到最近进场的最大值最小. 思路:二分+dlx搜索判定. ...
- hdu 5046 Airport 二分+重复覆盖
题目链接 给n个点, 定义两点之间距离为|x1-x2|+|y1-y2|. 然后要选出k个城市建机场, 每个机场可以覆盖一个半径的距离. 求在选出点数不大于k的情况下, 这个半径距离的最大值. 二分半径 ...
- [DLX反复覆盖] hdu 2828 Lamp
题意: 有N个灯M个开关 每一个灯的ON和OFF状态都能控制一个灯是否亮 给出N行,代表对于每一个灯 哪些开关的哪个状态能够使得第i个灯亮 思路: 这里须要注意一个问题 假设开关1的ON 状态和开关2 ...
- FZU 1686 神龙的难题(DLX反复覆盖)
FZU 1686 神龙的难题 pid=1686" target="_blank" style="">题目链接 题意:中文题 思路:每个1看成列, ...
- FZU 1686 神龙的难题 DLX反复覆盖
DLX反复覆盖: 须要一个A*函数剪支 Problem 1686 神龙的难题 Accept: 462 Submit: 1401 Time Limit: 1000 mSec Memory L ...
- HDOJ 2828 Lamp DLX反复覆盖
DLX反复覆盖模版题: 每一个开关两个状态.但仅仅能选一个,建2m×n的矩阵跑DLX模版.. .. Lamp Time Limit: 2000/1000 MS (Java/Others) Mem ...
- HDU 5046 Airport ( Dancing Links 反复覆盖 )
今年上海网络赛的一道题目 , 跟 HDU 2295 如出一辙 . 就是距离的计算一个是欧几里得距离 , 一个是曼哈顿距离 学完DLX感觉这题好水 ,就是一个裸的反复覆盖 注意下别溢出即可了 #incl ...
- hdu - 3498 - whosyourdaddy(反复覆盖DLX)
题意:N(2 ≤ N ≤ 55)个点,M(0 ≤ M ≤ N*N)条无向边,删除一个点会把与其相邻的点一起删掉.问最少删几次能够删掉全部点. 题目链接:pid=3498">http:/ ...
- HDU 4735 Little Wish~ lyrical step~(DLX , 反复覆盖)
解题思路: DLX 的模板题.反复覆盖. #include <stdio.h> #include <string.h> #include <iostream> #i ...
随机推荐
- angularJS友好URL实现 good
nginx部署 angularjs时的rewrite问题 使用h5+angularjs完成了一个项目 此项目在正式环境上使用nginx做webserver 此项目的入口在微信/微博分享中 由于分享时的 ...
- TPM 2.0 近况及模拟器开发
可信计算平台模块TPM 2.0的相关标准和技术准则由 TCG ( Trust Computing Group )于2011年前后提出,至今已经过了多次修改.该标准无疑将成为下一代可信计算平台模块的业界 ...
- 依赖于设备的位图(DDB) ,CreateCompatibleBitmap用法
DDB(Device-dependent bitmap)依赖于具体设备,这主要体现在以下两个方面: DDB的颜色模式必需与输出设备相一致.例如,如果当前的显示设备是256色模式,那么DDB必然也是25 ...
- Apache 2.2 到 2.4的不同
1.权限设定方式变更 2.2使用Order Deny / Allow的方式,2.4改用Require apache2.2: Order deny,allowDeny from allapache2.4 ...
- android Graphics(一):概述及基本几何图形绘制
前言:我最近想抽空研究研究android的各种特效,android的特效真是其它平台无法比拟的,而且一个漂亮的UI交互,会给APP增色不少,而学习特效之前,有关graphics绘图的基础知识是必不可少 ...
- C#中的DataTable简单使用Merge
//不同结构的DataTable追加第二个DataTable数据在对应行后的 简单使用//不同结构的DataTable追加在行后面的合并 DataTable dt = new DataTable(); ...
- ThinkPHP - 自定义扩展类库
首先在想要使用类库的地方建立文件夹,文件名称随意,不能使用class 然后在配置文件中: 'AUTOLOAD_NAMESPACE' => array( 'Lib' => './Lib', ...
- 【JavaScript】强制缓存刷新
1.在js引用时加入时间戳. <script> document.write('<script src="xxx.js?_dc='+new Date().getTime() ...
- java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource解决方法
java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource解决方法 只需把这三个commons-pool.jar ...
- iOS开发之视图控制器(UIViewController)
视图控制器应该在MVC设计模式中扮演控制层(C)的角色,UIViewController的职责对内管理与之关联的View,对外跟其他UIViewController通信和协调.一个视图控制器管理一个视 ...