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 & ...
随机推荐
- 第二百七十四、五、六天 how can I 坚持
三天小长假这么快就过去了,好快啊.基本都是在济南过的. 元旦.坐车回济南.下午在万科新里程看了一下午房子,没有买啊,93的现在八千六七,有点贵啊,户型也不是自己喜欢的. 晚上一块吃了个饭,还行,晚上在 ...
- Apache Spark GraphX
GraphX基于BSP模型,在Spark之上封装类似Pregel的接口,进行大规模同步全局的图计算,尤其是当用户进行多轮迭代时,基于Spark内存计算的优势尤为明显.
- Java缓存学习之一:缓存
一.缓存 1.什么是缓存? 缓存是硬件,是CPU中的组件,CPU存取数据的速度非常的快,一秒钟能够存取.处理十亿条指令和数据(术语:CPU主频1G),而内存就慢很多,快的内存能够达到几十兆就不错了,可 ...
- Gradle – Spring 4 MVC Hello World Example
In this tutorial, we will show you a Gradle + Spring 4 MVC, Hello World Example (JSP view), XML conf ...
- Umbraco 上传文件到另一个文件夹,而不是media files
If you want to upload there media files to another place in the same instance of IIS, for example a ...
- 命令行刷机教程( 以Linux系统为例 )
//第一步adb device // 如果不能cd AndroidSDK/platform-toolsadb kill-server adb start-server //第二步adb reboot ...
- .NET的Snk使用方法
保护你Asp.Net生成的DLL和Code不被别人反编译 大家做项目开发一般都是分层的,比如UI层,业务层,数据访问层.业务层引用数据访问层的DLL(比如 dataAccess.dll),并使用da ...
- php+gd库的源码安装
php+gd库的源码安装 PHP+GD安装 一.下载软件 gd-2.0.35.tar.gz http://www.boutell.com/gd/ jpegsrc.v6b. ...
- Winfrom强大的自动更新程序
推荐一:.Net 小型软件自动更新库(SimpAutoUpdater) http://www.fishlee.net/soft/simple_autoupdater/usage.html 下载地址:h ...
- PostgreSQL中,database,schema,table之间关系
从逻辑上看,schema,table,都是位于database之下. 首先,在postgres数据库下建立表(相当于建立在public schema下): [pgsql@localhost bin]$ ...