搜索(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个飞机场,使城市距离最近的飞机场的最长距离最小,求这 ...
随机推荐
- iOS9 http不能访问网络——在Xcode中将https改成http方式
=====================2016-01-29更新=========================== 最近做demo时,发现将https改成http方式略有小变 1. 没有改成ht ...
- jsonp调用webapi和mvc
webapi代码如下: public string Get(int id) { var callback = HttpContext.Current.Request["callback&qu ...
- [转]Javascript 严格模式详解
原文地址:http://www.ruanyifeng.com/blog/2013/01/javascript_strict_mode.html 一.概述 除了正常运行模式,ECMAscript 5添加 ...
- Java工具类:获取long型唯一ID
直接上代码: import java.text.SimpleDateFormat; import java.util.Date; /** * 获取long型唯一ID */ public class I ...
- HDU 3008 Warcraft(DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3008 题目大意:人有100血和100魔法,每秒增加 t 魔法(不能超过100).n个技能,每个技能消耗 ...
- 讲解最好的Python正则表达式
这篇文章转载自:http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html#!comments 这里非常感谢作者无私的贡献自己的成果. 请大 ...
- Mac苹果电脑加密视频播放器使用教程
1. 下载文件 https://pan.baidu.com/s/1slhFYuL 2. 操作流程 温馨提示 播放时,请务必保证播放设备联网(原因:用户名权限验证需要网络,播放后10秒即可关闭 ...
- REST接口规范
参考文章 这篇文章使用不同的method代表不同操作 http://www.cnblogs.com/tommyli/p/3913018.html 实际应用中(我们过去的应用) 则是直接使用url来代表 ...
- 修改win8系统中启动管理器的系统引导信息
最近用某软件做了个启动U盘,软件安装在电脑上,启动盘很快做完了,结果重启电脑的时候发现悲剧,windows启动后会显示出一个系统引导菜单,显示有3秒倒计时但是倒计时结束依然不能自动进入系统.. 然后. ...
- 可视化查看MongoDB - MongoVUE
OS:Window 7 1.下载安装MongoVUE:http://www.mongovue.com/downloads/ 2.运行MongoVUE,点击“OK”按钮,使用免费版 3.选择一个已经存在 ...