搜索(DLX重复覆盖模板):HDU 2295 Radar
Radar
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3684 Accepted Submission(s): 1398
cities of the Java Kingdom need to be covered by radars for being in a
state of war. Since the kingdom has M radar stations but only K
operators, we can at most operate K radars. All radars have the same
circular coverage with a radius of R. Our goal is to minimize R while
covering the entire city with no more than K radars.
input consists of several test cases. The first line of the input
consists of an integer T, indicating the number of test cases. The first
line of each test case consists of 3 integers: N, M, K, representing
the number of cities, the number of radar stations and the number of
operators. Each of the following N lines consists of the coordinate of a
city.
Each of the last M lines consists of the coordinate of a radar station.
All coordinates are separated by one space.
Technical Specification
1. 1 ≤ T ≤ 20
2. 1 ≤ N, M ≤ 50
3. 1 ≤ K ≤ M
4. 0 ≤ X, Y ≤ 1000
3 3 2
3 4
3 1
5 4
1 1
2 2
3 3
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const double eps=1e-;
const int N=,M=;
struct Point{int x,y;}c[N],r[N];
double sqr(double x){return 1.0*x*x;}
double dis(Point a,Point b){return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));} void P(int x){
printf("%d\n",x);
} int T,n,m,k,col[M],row[M];
int U[M],D[M],L[M],R[M];
int H[N],C[N],vis[N],cnt;
struct DLX{
void Init(int n,int m){
for(int i=;i<=m;i++){
L[i]=i-;R[i]=i+;
C[i]=;U[i]=D[i]=i;
}L[]=m;R[m]=;cnt=m;
for(int i=;i<=n;i++)H[i]=;
}
void Link(int r,int c){
C[c]+=;++cnt;
U[D[c]]=cnt;U[cnt]=c;
D[cnt]=D[c];D[c]=cnt;
row[cnt]=r;col[cnt]=c; if(H[r]){
L[R[H[r]]]=cnt;L[cnt]=H[r];
R[cnt]=R[H[r]];R[H[r]]=cnt;
}
else H[r]=L[cnt]=R[cnt]=cnt;
}
void Delete(int x){
for(int i=D[x];i!=x;i=D[i])
L[R[i]]=L[i],R[L[i]]=R[i];
}
void Resume(int x){
for(int i=U[x];i!=x;i=U[i])
L[R[i]]=i,R[L[i]]=i;
}
int F(){
int ret=;
for(int c=R[];c;c=R[c])vis[c]=;
for(int c=R[];c;c=R[c]){
if(vis[c])continue;ret+=;
for(int i=D[c];i!=c;i=D[i])
for(int j=R[i];j!=i;j=R[j])
vis[col[j]]=;vis[c]=;
}
return ret;
}
bool Dance(int dep){
if(!R[])return dep<=k;
if(dep+F()>k)return false;
int p=;
for(int i=R[];i;i=R[i])
if(!p||C[i]<C[p])p=i;
for(int i=D[p];i!=p;i=D[i]){
Delete(i);
for(int j=R[i];j!=i;j=R[j])Delete(j);
if(Dance(dep+))return true;
for(int j=L[i];j!=i;j=L[j])Resume(j);
Resume(i);
}
return false;
} bool Check(double d){
Init(m,n);
for(int i=;i<=m;i++)
for(int j=;j<=n;j++)
if(d>=dis(r[i],c[j]))
Link(i,j);
return Dance();
}
}dlx; int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<=n;i++)
scanf("%d%d",&c[i].x,&c[i].y);
for(int i=;i<=m;i++)
scanf("%d%d",&r[i].x,&r[i].y);
double l=,r=1e3;
while(r-l>=eps){
double mid=(l+r)/;
if(dlx.Check(mid))r=mid;
else l=mid;
}
printf("%.6f\n",l);
}
return ;
}
搜索(DLX重复覆盖模板):HDU 2295 Radar的更多相关文章
- DLX精确覆盖与重复覆盖模板题
hihoCoder #1317 : 搜索四·跳舞链 原题地址:http://hihocoder.com/problemset/problem/1317 时间限制:10000ms 单点时限:1000ms ...
- HDU 2295.Radar (DLX重复覆盖)
2分答案+DLX判断可行 不使用的估计函数的可重复覆盖的搜索树将十分庞大 #include <iostream> #include <cstring> #include < ...
- [ACM] HDU 2295 Radar (二分法+DLX 重复覆盖)
Radar Problem Description N cities of the Java Kingdom need to be covered by radars for being in a s ...
- HDU 2295 Radar 重复覆盖 DLX
题意: N个城市,M个雷达站,K个操作员,问雷达的半径至少为多大,才能覆盖所有城市.M个雷达中最多只能有K个同时工作. 思路: 二分雷达的半径,看每个雷达可以覆盖哪些城市,然后做重复覆盖,判断这个半径 ...
- HDU 2295 Radar (重复覆盖)
Radar Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 2295 Radar (二分 + Dancing Links 重复覆盖模型 )
以下转自 这里 : 最小支配集问题:二分枚举最小距离,判断可行性.可行性即重复覆盖模型,DLX解之. A*的启发函数: 对当前矩阵来说,选择一个未被控制的列,很明显该列最少需要1个行来控制,所以ans ...
- HDU 2295 Radar dancing links 重复覆盖
就是dancing links 求最小支配集,重复覆盖 精确覆盖时:每次缓存数据的时候,既删除行又删除列(这里的删除列,只是删除表头) 重复覆盖的时候:只删除列,因为可以重复覆盖 然后重复覆盖有一个估 ...
- hdu 2295 dlx重复覆盖+二分答案
题目大意: 有一堆雷达工作站,安放至多k个人在这些工作站中,找到一个最小的雷达监控半径可以使k个工作人所在的雷达工作站覆盖所有城市 二分半径的答案,每次利用dlx的重复覆盖来判断这个答案是否正确 #i ...
- HDU 5046 Airport【DLX重复覆盖】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5046 题意: 给定n个城市的坐标,要在城市中建k个飞机场,使城市距离最近的飞机场的最长距离最小,求这 ...
随机推荐
- IOS_OC_本地推送知识总结
知识点介绍 一. 推送通知介绍(了解) 二. 本地推送通知 本地通知的基本使用 本地通知的不常用属性 删除重复的通知 通知的处理1-跳转界面 通知的处理2-程序退出 分类的设置/快捷回复 一. 推送通 ...
- form 表单 action 参数 接收不了
<form method="get" action="/test/index.php?mod=123456" > <input type=&q ...
- C语言链表全操作(增,删,改,查,逆序,递增排序,递减排序,链式队列,链式栈)
一,数据结构——链表全操作: 链表形式: 其中,每个节点(Node)是一个结构体,这个结构体包含数据域,指针域,数据域用来存放数据,指针域则用来指向下一个节点: 特别说明:对于单链表,每个节点(Nod ...
- Codevs 4560 NOIP2015 D2T2 子串
> 4560 NOIP2015 D2T2 子串 时间限制: 1 s 空间限制: 128000 KB 题目等级:黄金 Gold 题目描述 Description 有两个仅包含小写英文字母的字符串A ...
- Google C++编程风格指南
作者:Hawstein 出处:http://hawstein.com/posts/google-cpp-style-guide.html 前言 越来越发现一致的编程风格的重要性,于是把Google的C ...
- ubuntu apt-get
近期重新拿起linux的书看了下,整理了一下linux的命令. ubuntu预装了APT和dpkg ,“APT”是 “Advanced Package Tool”的简写,“dpkg ”是“Debian ...
- wpf+xml实现的一个随机生成早晚餐的小demo
话说每到吃完的时间就发愁,真的不知道该吃什么,然后就想到做一个生成吃什么的小软件,既然这个软件如此的简单,就打算用wpf开发吧,也不用数据库了,直接保存在xml中就可以了 程序整体结构如下图 首先我写 ...
- Kafka Offset Storage
1.概述 目前,Kafka 官网最新版[0.10.1.1],已默认将消费的 offset 迁入到了 Kafka 一个名为 __consumer_offsets 的Topic中.其实,早在 0.8.2. ...
- ios:如何将自己编写的软件放到真正的iPhone上运行(转)
想要将自己编写的软件放到真正的iPhone上去运行,首先你需要成为Apple Developer计划的成员.其次,你需要设置程序ID和认证书,在这之后你就可以在你指定的iPhone上运行你的程序了.下 ...
- 解决在HTTPS页面里嵌套HTTP页面浏览器block的问题
问题描述: 浏览器默认是不允许在HTTPS里面引用HTTP页面的,ie下面会弹出提示框提示是否显示不安全的内容,一般都会弹出提示框,用户确认后才会继续加载,但是chrome下面直接被block掉,只在 ...