HDU 5046
同样是二分+DLX即可。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define LL __int64
using namespace std; const int maxn=;
const int maxc=;
const int maxr=;
const int inf=0x3f3f3f3f;
const double rinf=1e10;
int L[maxn], R[maxn], D[maxn], U[maxn], C[maxn];
int S[maxc], H[maxr], size;
int N,M,K;
struct City{
LL x,y;
}cities[maxr];
struct Radar{
int x,y;
}radar[maxc];
LL map[][];
///²»ÐèÒªSÓò
void Link(int r, int c)
{
S[c]++; C[size]=c;
U[size]=U[c]; D[U[c]]=size;
D[size]=c; U[c]=size;
if(H[r]==-) H[r]=L[size]=R[size]=size;
else {
L[size]=L[H[r]]; R[L[H[r]]]=size;
R[size]=H[r]; L[H[r]]=size;
}
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;
} int h(){///Óþ«È·¸²¸ÇÈ¥¹ÀËã¼ôÖ¦
int ret=;
bool vis[maxc];
memset (vis, false, sizeof(vis));
for (int i=R[]; i; i=R[i])
{
if(vis[i])continue;
ret++;
vis[i]=true;
for (int j=D[i]; j!=i; j=D[j])
for (int k=R[j]; k!=j; k=R[k])
vis[C[k]]=true;
}
return ret;
} int ans;
bool Dance(int k){
int t=h();
if(t+k>M) return false; //¸ù¾Ý¾ßÌåÎÊÌâÑ¡ÔñÏÞÖÆËÑË÷Éî¶È»òÖ±½ÓÇó½â¡£ A*Ëã·¨£¬´Ë´¦Ö»Çó×îÓŽâ
if(!R[]){
return true;
}
int c=R[];
for (int i=R[]; i; 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(k+)) return true;
for (int j=L[i]; j!=i; j=L[j])
resume(j);
resume(i);
}
return false;
} void initL(int x){///col is 1~x,row start from 1
// ans=inf;
for (int i=; i<=x; ++i){
S[i]=;
D[i]=U[i]=i;
L[i+]=i; R[i]=i+;
}///¶ÔÁбíÍ·³õʼ»¯
R[x]=;
size=x+;///ÕæÕýµÄÔªËØ´Óm+1¿ªÊ¼
memset (H, -, sizeof(H));
///markÿ¸öλÖõÄÃû×Ö
} LL dabs(LL a){
if(a<) return -a;
return a;
} LL dist(int i,int j){
return (dabs(cities[i].x-cities[j].x)+dabs(cities[i].y-cities[j].y));
} void BuildLink(LL r){
for(int i=;i<=N;i++){
for(int j=;j<=N;j++){
if(map[i][j]<=r)
Link(i,j);
}
}
} void bin(){
LL Ans;
LL l=,r=20000000050ll,m;
ans=inf;
while(l<=r){
m=(l+r)/2ll;
ans=inf;
initL(N);
BuildLink(m);
if(Dance())
{ Ans=m; r=m-; }
else l=m+;
}
printf("%I64d\n",Ans);
} int main(){
int T,t=;
scanf("%d",&T);
while(T--){
scanf("%d%d",&N,&M);
for(int i=;i<=N;i++)
scanf("%I64d%I64d",&cities[i].x,&cities[i].y);
for(int i=;i<=N;i++){
for(int j=;j<=N;j++){
map[i][j]=dist(i,j);
// cout<<map[i][j]<<" ";
}
// cout<<endl;
}
printf("Case #%d: ",++t);
/* if(M==0){
cout<<"Yes"<<endl;
int Ans=inf;
for(int i=2;i<=N;i++){
if(map[1][i]<Ans) Ans=map[1][i];
}
printf("%d\n",Ans);
}
else*/
bin();
}
return ;
}
HDU 5046的更多相关文章
- HDU 5046 Airport(DLX反复覆盖)
HDU 5046 Airport 题目链接 题意:给定一些机场.要求选出K个机场,使得其它机场到其它机场的最大值最小 思路:二分+DLX反复覆盖去推断就可以 代码: #include <cstd ...
- HDU 5046 Airport(dlx)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5046 题意:n个城市修建m个机场,使得每个城市到最近进场的最大值最小. 思路:二分+dlx搜索判定. ...
- hdu 5046 二分+DLX模板
http://acm.hdu.edu.cn/showproblem.php?pid=5046 n城市建k机场使得,是每个城市最近机场的距离的最大值最小化 二分+DLX 模板题 #include < ...
- HDU 5046 Airport【DLX重复覆盖】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5046 题意: 给定n个城市的坐标,要在城市中建k个飞机场,使城市距离最近的飞机场的最长距离最小,求这 ...
- HDU 5046 Airport ( Dancing Links 反复覆盖 )
今年上海网络赛的一道题目 , 跟 HDU 2295 如出一辙 . 就是距离的计算一个是欧几里得距离 , 一个是曼哈顿距离 学完DLX感觉这题好水 ,就是一个裸的反复覆盖 注意下别溢出即可了 #incl ...
- hdu 5046 Airport 二分+重复覆盖
题目链接 给n个点, 定义两点之间距离为|x1-x2|+|y1-y2|. 然后要选出k个城市建机场, 每个机场可以覆盖一个半径的距离. 求在选出点数不大于k的情况下, 这个半径距离的最大值. 二分半径 ...
- (中等) HDU 5046 Airport ,DLX+可重复覆盖+二分。
Description The country of jiuye composed by N cites. Each city can be viewed as a point in a two- d ...
- NOI考前乱写
还有13天NOI,把各种乱七八糟的算法都重新过一遍还是比较有必要的... //HDU 5046 Airport //DancingLink #include<iostream> #incl ...
- KUANGBIN带你飞
KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题 //201 ...
随机推荐
- C语言相关
标准输入输出 格式化输入输出 int a,b; int arr[10]={1},*p=&b; double d; char ch,str[30]; scanf("%d%d" ...
- javascript从作用域链的角度看闭包
闭包 闭包是一个能访问外部函数定义的变量的函数. 为什么? 当访问一个变量时,解释器会首先在当前作用域查找标示符,如果没有找到,就去父作用域找,直到找到该变量的标示符或者不再存在父作用域了,这就是作用 ...
- Django day08 多表操作 (四) 一对多, 多对多连续跨表查询
一对多 # 基于双下划线的一对多查询 # 查询出版社为上海出版社的所有图书 # ret = Publish.objects.filter(name='上海出版社').values('book__nam ...
- Django day08 多表操作 (二) 添加表记录
一: 一对多 1. 一对多新增 两种方式: publish = 对象 publish_id = id 1. publish_id 和 publish 的区别就是: 1)publish_id 可 ...
- Elasticserach 同步索引报错:ElasticSearch ClusterBlockException[blocked by: [FORBIDDEN/12/index read-only / allow delete (api)]
欢迎关注个人微信公众号: 小哈学Java, 文末分享阿里 P8 高级架构师吐血总结的 <Java 核心知识整理&面试.pdf>资源链接!! 个人网站: https://www.ex ...
- C# html生成PDF遇到的问题,从iTextSharp到wkhtmltopdf
我们的网站业务会生成一个报告,用网页展示出来,要有生成pdf并下载的功能,关键是生成pdf. 用内容一段段去拼pdf,想想就很崩溃,所以就去网上找直接把html生成pdf的方法. 网上资料大部分都是用 ...
- Application windows are expected to have a root view controller at the end of application launch
今天把Xcode升级了,模拟器 用的12.1的系统,运行时发现项目总是崩溃,采用9.3系统的测试机发现错误日志如下: Application windows are expected to have ...
- [编码]ASCII、GBK、Unicode(万国码) 和 UTF-8
American ASCII编码 (American Standard Code for Information Interchange,美国信息互换标准代码) China gbk编码 ...
- less 安装和webstorm的使用
1.less 的安装 npm install -g less 2.less安装成功 3.less安装成功后,在webstorm中进行配置.file——>settings:弹出settings框, ...
- (转)基于Metronic的Bootstrap开发框架经验总结(5)--Bootstrap文件上传插件File Input的使用
http://www.cnblogs.com/wuhuacong/p/4774396.html Bootstrap文件上传插件File Input是一个不错的文件上传控件,但是搜索使用到的案例不多,使 ...