题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2295

题意::一个国家有n个城市,有m个地方可以建造雷达,最多可以建K个雷达(K>=1 && K<=m),问雷达最短的探测半径,才能使n个城市都能探测到。

分析:二分距离,然后再DLX重复覆盖来判断。n个城市排成n列,再将每个城市当成一行,在二分的距离内能到达的城市在该列标为1,然后问题就转换成选至多k行来覆盖所有列,并且是可重复覆盖。

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define LL long long
#define mod 10007
#define inf 0x3f3f3f3f
#define N 100010
#define FILL(a,b) (memset(a,b,sizeof(a)))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const int maxnode=;
const int MaxN=;
const int MaxM=;
int k;
struct DLX
{
int n,m,size;
int U[maxnode],D[maxnode],R[maxnode],L[maxnode],Row[maxnode],Col[maxnode];
int H[MaxN],S[MaxM];
int ansd,ans[MaxN];
void init(int _n,int _m)
{
n=_n;m=_m;
for(int i=;i<=m;i++)
{
S[i]=;
U[i]=D[i]=i;
L[i]=i-;
R[i]=i+;
}
R[m]=;L[]=m;
size=m;
for(int i=;i<=n;i++)H[i]=-;
}
void Link(int r,int c)
{
++S[Col[++size]=c];
Row[size]=r;
D[size]=D[c];
U[D[c]]=size;
U[size]=c;
D[c]=size;
if(H[r]<)H[r]=L[size]=R[size]=size;
else
{
R[size]=R[H[r]];
L[R[H[r]]]=size;
L[size]=H[r];
R[H[r]]=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;
} bool vis[maxnode];
int h()
{
int res=;
for(int c=R[];c!=;c=R[c])vis[c]=true;
for(int c=R[];c!=;c=R[c])
if(vis[c])
{
res++;
vis[c]=false;
for(int i=D[c];i!=c;i=D[i])
for(int j=R[i];j!=i;j=R[j])
vis[Col[j]]=false;
}
return res;
}
bool Dance(int d)//d为递归深度
{
if(d+h()>k)return false;
if(R[]==)//找到解
return d<=k;
//找S最小的C列
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])//用结点i所在的行覆盖第c列
{
Remove(i);
for(int j=R[i];j!=i;j=R[j])Remove(j);//删除节结点i所在行覆盖第c列
if(Dance(d+))return true;
for(int j=L[i];j!=i;j=L[j])Resume(j);// 恢复
Resume(i);
}
return false;
}
};
DLX g;
struct node
{
int x,y;
}s[MaxN],c[MaxN];
const double eps=1e-;
double dist(node a,node b)
{
return sqrt((double)((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)));
}
int main()
{
int T,n,m;
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",&s[i].x,&s[i].y);
double l=,r=1e8,ans;
while(r-l>=eps)
{
double mid=(l+r)/;
g.init(m,n);
for(int i=;i<=m;i++)
for(int j=;j<=n;j++)
if(dist(s[i],c[j])<mid-eps)
g.Link(i,j);
if(g.Dance())r=mid-eps,ans=mid;
else l=mid+eps;
}
printf("%.6lf\n",ans);
}
}

hdu2295(重复覆盖+二分)的更多相关文章

  1. HDU5046 Airport dancing links 重复覆盖+二分

    这一道题和HDU2295是一样 是一个dancing links重复覆盖解决最小支配集的问题 在给定长度下求一个最小支配集,只要小于k就行 然后就是二分答案,每次求最小支配集 只不过HDU2295是浮 ...

  2. hdu3656Fire station(DLX重复覆盖 + 二分)

    题目请戳这里 题目大意:一个城市n个点,现在要建m个消防站,消防站建在给定的n个点中.求建m个消防站后,m个消防站要覆盖所有的n个点的覆盖半径最小. 题目分析:重复覆盖问题,DLX解决.不过要求覆盖半 ...

  3. hdu5046(重复覆盖+二分)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5046 题意:要在n个城市里建造不超过k个机场覆盖所有城市,问机场城市之间最大距离最小为多少. 分析:二 ...

  4. hdu 2295 dlx重复覆盖+二分答案

    题目大意: 有一堆雷达工作站,安放至多k个人在这些工作站中,找到一个最小的雷达监控半径可以使k个工作人所在的雷达工作站覆盖所有城市 二分半径的答案,每次利用dlx的重复覆盖来判断这个答案是否正确 #i ...

  5. (中等) 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 ...

  6. (中等) HDU 2295 , DLX+重复覆盖+二分。

    Description N cities of the Java Kingdom need to be covered by radars for being in a state of war. S ...

  7. hdu5064 DLX可重复覆盖+二分

    这题题意是 给了n个城市 在其中小于等于k个城市建立机场然后 使得最远的那个离机场的城市距离最短 二分答案 ,我们对于每次的mid 重新建图然后再来一次DLX,每个点可以覆盖的点建立一条联系就ok了 ...

  8. hdu2295DLX重复覆盖+二分

    题目是说 给了n个城市 m个雷达 你只能选择其中的k个雷达进行使用 你可以设置每个雷达的半径,最后使得所有城市都被覆盖,要求雷达的半径尽可能的小(所有雷达的半径是一样的) 二分最小半径,然后每次重新建 ...

  9. hdu 2295 Radar 重复覆盖+二分

    题目链接 给m个雷达, n个城市, 以及每个城市的坐标, m个雷达里只能使用k个, 在k个雷达包围所有城市的前提下, 求最小半径. 先求出每个雷达到所有城市的距离, 然后二分半径, 如果距离小于二分的 ...

随机推荐

  1. C# - ref

    The ref keyword causes an argument to be passed by reference, not by value. The effect of passing by ...

  2. appium 真机测试问题 出现 instruments crashed on startup

    1.appium 真机测试的时候 instruments crashed on startup,必须在真机上打开UI Automation 在设置里: Developer->Enable UI ...

  3. Delphi安装NT服务程序时(不出现提示信息)

    如果我们不加上"/silent",那么Delphi在安装和卸载NT服务程序时候,都会出现一个提示信息,不希望出现这个提示信息,那么使用如下命令: 1,安装:“你的nt程序 /ins ...

  4. find-a-jar-file-given-the-class-name

    Save this as findclass.sh (or whatever), put it on your path and make it executable: #!/bin/sh find ...

  5. java Date 和 javascript Date

    近期写一个页面.上面要展示下日期. 在Java中生成了Date.然后将这个Date通过velocity送入vm模板其中 代码例如以下: var dates = new Date("$!{pp ...

  6. 地大邀请赛d

    Problem D: Tetrahedron Inequality Time Limit: 1 Sec   Memory Limit: 128 MB Submit: 15   Solved: 3 [ ...

  7. RealThinClient学习(一)

    服务端代码: unit RtcHttpServer; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, ...

  8. [Android学习笔记]view的layout过程学习

    View从创建到显示到屏幕需要经历几个过程: measure -> layout -> draw measure过程:计算view所占屏幕大小layout过程:设置view在屏幕的位置dr ...

  9. That's life,多一些韧性,才有更多的任性(转)

    如果是正确的选择,就不要遵守太多规则. 若有容纳之心,便丰富了自己,也闪了他人,平常心,平常事 阅读,是保持时尚最节约的方式,也是快乐的源泉.可人生难免失意,有了快乐的能力,还应有面对沮丧的心胸. 相 ...

  10. frontend http 前端名字定义问题

    https://www.winfae.com/admin/api/menu haproxy 日志: Jun 24 13:04:49 localhost haproxy[14817]: 115.236. ...