有n个城市,\(m\)个雷达,\(k\)个操作员,每个操作员只能操作一个雷达。每个雷达的覆盖范围是一个以雷达坐标为中心的圆,所有雷达的覆盖半径是相同的。

现在给出这\(n\)个城市,\(m\)个雷达的坐标,问雷达覆盖半径最小是多少,让所有城市都可以被雷达覆盖到。

\(T\le 1000,n,m,k\le 50,x,y\le 1000\)。

分析

二分答案,转化成判定性问题。这是一个最小支配集问题,已经被证明是NP难的,没有多项式的解法,所以使用搜索。又注意到这是一个覆盖的问题,可以使用Dancing Links数据结构来优化搜索。

这与DLX的一般问题,精确覆盖问题是不同的,因为一个城市可以被多个雷达覆盖,所以这是一个重复覆盖问题。这同样可以用DLX解决,因为它只是一个加速删除和回溯的数据结构而已。

重复覆盖,就是说一个列可以被覆盖多次,但每一列都要被覆盖。这样的话,我们只要每次在删除和回溯的时候,都只删除当前选择的这一行的所有元素的那些列,而不继续删除那些节点所在的行。这个在实现上有一些技巧。


for (int i=p[first].d;i!=first;i=p[i].d) {
del(i);
for (int j=p[i].r;j!=i;j=p[j].r) del(j);
bool ret=dance(now+1);
if (ret) return ret;
for (int j=p[i].l;j!=i;j=p[j].l) back(j);
back(i);
}

我们删除一列不是从列标开始删除,而是从当前的节点循环删除一轮,并且不删除当前节点。这是为了方便继续往下遍历,而且不删当前节点是没有影响的,因为这列上除了当前节点的点都被删掉了,所以不会访问到。而从行访问也是不需要的,所以可以这样做。

然而这样会TLE,因为在重复覆盖问题中,节点个数减少得很慢,导致算法的效率降低。所以我们一般需要加一些剪枝(其实一般都要加的),例如这题中的估价剪枝。

如果当前的答案加上最少需要再选多少行才能覆盖(只能估少,不能估多),已经大于\(k\)了,那么就可以剪掉。这个估价的方法是,枚举当前存在的每一列,如果没有tic就便利这一列有关的所有行,把所有行有关的列都打上tic,这算作选了一次,因为选的次数至少是这么多。

代码

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const double eps=1e-8;
const int maxn=55;
const int maxm=maxn*maxn;
struct cord {
double x,y;
} city[maxn],radar[maxn];
double dist(cord &a,cord &b) {
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int n,m,k;
struct node {
int l,r,u,d,col,row;
};
struct DLX {
node p[maxm];
int tot,last[maxn],size[maxn];
bool tic[maxn];
void clear() {
memset(p,0,sizeof p);
memset(last,0,sizeof last),memset(size,0,sizeof size);
tot=n;
p[0]=(node){n,1,0,0,0,0};
for (int i=1;i<=n;++i) {
p[i]=(node){i-1,i+1,i,i,0,i};
last[i]=i;
}
p[n].r=0;
}
void build(int row,int a[],int len) {
if (!len) return;
p[++tot]=(node){tot,tot,last[a[1]],p[last[a[1]]].d,a[1],row};
p[p[tot].u].d=p[p[tot].d].u=last[a[1]]=tot;
++size[a[1]];
for (int i=2;i<=len;++i) {
int x=a[i];
p[++tot]=(node){tot-1,p[tot-1].r,last[x],p[last[x]].d,x,row};
p[p[tot].l].r=p[p[tot].r].l=p[p[tot].u].d=p[p[tot].d].u=last[x]=tot;
++size[x];
}
}
void del(int c) {
for (int i=p[c].d;i!=c;i=p[i].d) p[p[i].l].r=p[i].r,p[p[i].r].l=p[i].l,--size[p[i].col];
}
void back(int c) {
for (int i=p[c].u;i!=c;i=p[i].u) p[p[i].l].r=p[p[i].r].l=i,++size[p[i].col];
}
int mi() {
memset(tic,0,sizeof tic);
int ret=0;
for (int i=p[0].r;i;i=p[i].r) if (!tic[i]) {
++ret;
tic[i]=true;
for (int j=p[i].d;j!=i;j=p[j].d) for (int q=p[j].r;q!=j;q=p[q].r) tic[p[q].col]=true;
}
return ret;
}
bool dance(int now) {
if (!p[0].r) return now<=k;
if (now+mi()>k) return false;
int first=p[0].r;
for (int i=p[0].r;i;i=p[i].r) if (size[i]<size[first]) first=i;
for (int i=p[first].d;i!=first;i=p[i].d) {
del(i);
for (int j=p[i].r;j!=i;j=p[j].r) del(j);
bool ret=dance(now+1);
if (ret) return ret;
for (int j=p[i].l;j!=i;j=p[j].l) back(j);
back(i);
}
return false;
}
} dlx;
bool ok(double rad) {
dlx.clear();
for (int i=1;i<=m;++i) {
static int c[maxn];
int tot=0;
for (int j=1;j<=n;++j)
if (dist(radar[i],city[j])<=rad)
c[++tot]=j;
dlx.build(i,c,tot);
}
bool flag=dlx.dance(0);
return flag;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("test.in","r",stdin);
#endif
int T;
scanf("%d",&T);
while (T--) {
scanf("%d%d%d",&n,&m,&k);
for (int i=1;i<=n;++i) scanf("%lf%lf",&city[i].x,&city[i].y);
for (int i=1;i<=m;++i) scanf("%lf%lf",&radar[i].x,&radar[i].y);
double l=0,r=2000,ans,mid;
while (fabs(l-r)>eps) {
mid=(l+r)/2;
if (ok(mid)) ans=mid,r=mid; else l=mid;
}
printf("%.6lf\n",ans);
}
return 0;
}

hdu2295-Radar的更多相关文章

  1. HDU2295 Radar —— Dancing Links 可重复覆盖

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2295 Radar Time Limit: 2000/1000 MS (Java/Others)     ...

  2. HDU2295 Radar (DLX)

    下面的代码99%参考了这个网站http://www.cnblogs.com/183zyz/archive/2011/08/07/2130193.html 人生的第一道DLX肯定是需要作一些参考的啦. ...

  3. Dancing Links 专题总结

    算法详细:Dancing Links博客 1.精确覆盖: ZOJ3209 Treasure Map HUST1017 Exact cover POJ3074 Sudoku 2.可重复覆盖: HDU22 ...

  4. HDU 2295 Radar (重复覆盖)

    Radar Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  5. GNU Radio Radar Toolbox

    GNU Radio Radar Toolbox Install guide Change to any folder in your home directory and enter followin ...

  6. radar js

    <!doctype html> <html> <head> <meta charset="utf-8"> <link href ...

  7. [POJ1328]Radar Installation

    [POJ1328]Radar Installation 试题描述 Assume the coasting is an infinite straight line. Land is in one si ...

  8. Radar Installation

    Radar Installation 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/C 题目: De ...

  9. Radar Installation(贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 56826   Accepted: 12 ...

  10. 贪心 POJ 1328 Radar Installation

    题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...

随机推荐

  1. 20145226夏艺华《网络对抗》第一次实验拓展:shellcode注入+return-to-libc

    20145226夏艺华<网络对抗>第一次实验拓展:shellcode注入+return-to-libc shellcode注入实践 编写shellcode 编写shellcode已经在之前 ...

  2. 北京Uber优步司机奖励政策(1月11日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  3. LimitedConcurrencyLevelTaskScheduler

    //-------------------------------------------------------------------------- // // Copyright (c) Mic ...

  4. 请求头(request)和响应头(response)

    说一说常见的请求头和相应头都有什么呢? 1)请求(客户端->服务端[request]) GET(请求的方式) /newcoder/hello.html(请求的目标资源) HTTP/1.1(请求采 ...

  5. uvaoj455Periodic Strings(枚举)

    A character string is said to have period k if it can be formed by concatenating one or more repetit ...

  6. lintcode204 单例

    单例   单例 是最为最常见的设计模式之一.对于任何时刻,如果某个类只存在且最多存在一个具体的实例,那么我们称这种设计模式为单例.例如,对于 class Mouse (不是动物的mouse哦),我们应 ...

  7. Android开发-API指南-<activity>

    <activity> 英文原文:http://developer.android.com/guide/topics/manifest/activity-element.html 采集(更新 ...

  8. 1208: [HNOI2004]宠物收养所

    1208: [HNOI2004]宠物收养所 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 12030 Solved: 4916 Description ...

  9. maven项目中没有resource文件夹的问题

    之前使用eclipse创建maven项目,文件夹都是建好的,这几次创建,都没有resource文件夹,需要手动创建resource. 现象描述 在eclipse中,创建maven项目有两种方式: 一种 ...

  10. Java 单例模式探讨

    以下是我再次研究单例(Java 单例模式缺点)时在网上收集的资料,相信你们看完就对单例完全掌握了 Java单例模式应该是看起来以及用起来简单的一种设计模式,但是就实现方式以及原理来说,也并不浅显哦. ...