HDU 2295 Radar (DLX + 二分)
Radar
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2882 Accepted Submission(s): 1113
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 <cstdlib>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <cstdio>
using namespace std; struct Node
{
double x,y;
}; const int HEAD = ;
const int SIZE = ;
int N,M,K;
double RADAR[SIZE][SIZE];
Node CITY[SIZE];
bool VIS[SIZE];
int U[SIZE * SIZE],D[SIZE * SIZE],L[SIZE * SIZE],R[SIZE * SIZE],C[SIZE * SIZE],S[SIZE * SIZE]; int comp(const void * a,const void * b);
int h(void);
void debug(int count);
void ini(void);
bool dancing(int);
void remove(int);
void resume(int); int main(void)
{
int t;
double x,y; scanf("%d",&t);
while(t --)
{
scanf("%d%d%d",&N,&M,&K);
for(int i = ;i < N;i ++)
scanf("%lf%lf",&CITY[i].x,&CITY[i].y);
for(int i = ;i < M;i ++)
{
scanf("%lf%lf",&x,&y);
for(int j = ;j < N;j ++)
RADAR[i][j] = sqrt(pow(CITY[j].x - x,) + pow(CITY[j].y - y,));
} double l = ,r = ;
double mid = ;
while(r - l > 1e-)
{
mid = (l + r) / ;
ini(); int count = N + ;
for(int i = ;i < M;i ++)
{
int first = count;
for(int j = ;j < N;j ++)
if(RADAR[i][j] <= mid)
{
R[count] = count + ;
L[count] = count - ;
U[count] = U[j + ];
D[count] = j + ; D[U[j + ]] = count;
U[j + ] = count; C[count] = j + ;
S[j + ] ++;
count ++;
}
L[first] = count - ;
if(first != count)
R[count - ] = first;
}
//debug(count );
if(dancing())
r = mid;
else
l = mid;
} printf("%lf\n",mid);
} return ;
} void ini(void)
{
R[HEAD] = ;
L[HEAD] = N;
for(int i = ;i <= N;i ++)
{
L[i] = i - ;
R[i] = i + ;
U[i] = D[i] = C[i] = i;
S[i] = ;
}
R[N] = HEAD;
} bool dancing(int k)
{
if(R[HEAD] == HEAD)
return true;
if(k + h() > K)
return false; int c = R[HEAD];
for(int i = R[HEAD];i != HEAD;i = R[i])
if(S[c] > S[i])
c = i; for(int i = D[c];i != c;i = D[i])
{
remove(i);
for(int j = R[i];j != i;j = R[j])
remove(j);
if(dancing(k + ))
return true;
for(int j = L[i];j != i;j = L[j])
resume(j);
resume(i);
} return false;
} 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 = D[c];i != c;i = D[i])
{
L[R[i]] = i;
R[L[i]] = i;
}
} void debug(int count)
{
for(int i = ;i < count;i ++)
printf("%d U:%d D:%d L:%d R:%d C:%d S:%d\n",i,U[i],D[i],L[i],R[i],C[i],S[i]);
cout << endl << endl;
} int h(void)
{
fill(VIS,VIS + SIZE,false); int count = ;
for(int i = R[HEAD];i;i = R[i])
if(!VIS[i])
{
count ++;
VIS[i] = true;
for(int j = D[i];j != i;j = D[j])
for(int k = R[j];k != j;k = R[k])
VIS[C[k]] = true;
}
return count;
}
HDU 2295 Radar (DLX + 二分)的更多相关文章
- HDU 2295 Radar (二分 + Dancing Links 重复覆盖模型 )
以下转自 这里 : 最小支配集问题:二分枚举最小距离,判断可行性.可行性即重复覆盖模型,DLX解之. A*的启发函数: 对当前矩阵来说,选择一个未被控制的列,很明显该列最少需要1个行来控制,所以ans ...
- 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 ...
- 搜索(DLX重复覆盖模板):HDU 2295 Radar
Radar Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- hdu 2295 Radar 重复覆盖+二分
题目链接 给m个雷达, n个城市, 以及每个城市的坐标, m个雷达里只能使用k个, 在k个雷达包围所有城市的前提下, 求最小半径. 先求出每个雷达到所有城市的距离, 然后二分半径, 如果距离小于二分的 ...
- 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 重复覆盖
就是dancing links 求最小支配集,重复覆盖 精确覆盖时:每次缓存数据的时候,既删除行又删除列(这里的删除列,只是删除表头) 重复覆盖的时候:只删除列,因为可以重复覆盖 然后重复覆盖有一个估 ...
- 【HDOJ】2295 Radar
DLX+二分. /* 2295 */ #include <iostream> #include <string> #include <map> #include & ...
随机推荐
- Apache Spark GraphX的特点
GraphX 的特点是离线计算.批量处理,基于同步的 BSP 模型(Bulk Synchronous Parallel Computing Model,整体同步并行计算模型),这样的优势在于可以提升数 ...
- 修改Map中确定key对应的value问题
今天在码代码的时候出现一个没有预料的问题: 先看下面的代码: public static void main(String[] args) { String[] files=new String[]{ ...
- js特效-仿照html属性title写一个弹出标题样式
问题场景:商品描述,当营业员给客户介绍时会看着这些弹出标题来给客户讲解描述,一般采用html中属性title来实现,但是有些商品描述太长,这些title在IE浏览器中大约展示5s,营业员需要多次移动鼠 ...
- javascript中对象的每个实例都具有的属性和方法
- String中的Indexof,LastIndexOf, Indexofany,LastIndexOfAny 的区别
本文转载自 http://www.cnblogs.com/qinying/archive/2008/09/22/1295730.html 定位子串是指在一个字符串中寻找其中包含的子串或者某个字符.在S ...
- Web开源框架大汇总
Struts 项目简介信息 Struts是一个基于Sun J2EE平台的MVC框架,主要是采用Servlet和JSP技术来实现的.由于Struts能充分满足应用开发的需求,简单易用,敏捷迅速,在过去的 ...
- git乱码问题
直接看连接吧. http://my.oschina.net/lujian863/blog/168837
- 普通Jquery的ajax判断重复和formvalidator的ajaxValidator区别
示例:1.ajax版: $("#txtTitle").blur(function () { $.ajax({ ...
- protoc-gen-lua
lua里使用proto buffer protoc-gen-lua 官方不维护了,自己维护个:protoc-gen-lua int64支持,将64位int转换成lua的string. message相 ...
- 如何同时启动多个Tomcat服务
在项目开发中,有时会需要同时启动多个Tomcat服务,如果直接启动多个的话,会报以下错误: Port busy xxxx java.net.SocketException: Unrecognized ...