搜索(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个飞机场,使城市距离最近的飞机场的最长距离最小,求这 ...
随机推荐
- linux/windows系统oracle数据库简单冷备同步
linux/windows系统oracle数据库简单冷备同步 我们有一个财务系统比较看重财务数据的安全性,同时我们拥有两套系统,一个生产环境(linux),一个应急备份环境(windows).备份环境 ...
- Cesium的api之关于viewer(二)
1.构建一个viewer,如下创建:options的参数根据实际情况,进行设定 var viewer = new Cesium.Viewer('cesiumContainer', { //Start ...
- HTML<label> 标签的 for 属性
定义和用法 for 属性规定 label 与哪个表单元素绑定. 隐式和显式的联系 标记通常以下面两种方式中的一种来和表单控件相联系:将表单控件作为标记标签的内容,这样的就是隐式形式,或者为 <l ...
- java新手笔记2 数据类型
1.注释 /** doc注释 * 类说明信息 */ //声明类 文件名与类名一致 public class World {//类定界符 //声明方法 main方法 public static void ...
- java Email发送及中文乱码处理。
public class mail { private String pop3Server=""; private String smtpServer=""; ...
- mysql 根据某个字段将多条记录的某个字段拼接成一个字段
未合并情况 SELECT a.id, b.name AS "role" FROM sys_user a INNER JOIN sys_user_role c ON a.id=c.u ...
- mysql 账户操作
1.授权 mysql> grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by ‘连接口令’; 权限1,权限2,…权限n代表selec ...
- Codevs 1427 特种部队(双路DP)
1427 特种部队 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 黄金 Gold 题目描述 Description 某特种部队接到一个任务,需要潜入一个仓库.该部队士兵分为两路,第一 ...
- PDF.NET+EasyUI实现只更新修改的字段
PDF.NET 在我看来是目前最简单易用而且高效的orm框架之一,感谢作者深蓝医生 实现的功能是easyui的行内编辑,用到了爱看书不识字的datagrid仿extjs的行内编辑 都是牛人啊. 201 ...
- asmdisk 丢失问题一次记录
环境 vm12 workstation ,11.2R 在安装RAC 第二台机器不显示磁盘的是问题 , oracleasm listdisks 查询没有结果 , 于是执行 oracleasm scand ...