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 & ...
随机推荐
- Spark SQL概念学习系列之如何使用 Spark SQL(六)
val sqlContext = new org.apache.spark.sql.SQLContext(sc) // 在这里引入 sqlContext 下所有的方法就可以直接用 sql 方法进行查询 ...
- 【现代程序设计】【homework-07】
C++11 中值得关注的几大变化 1.Lambda 表达式 Lambda表达式来源于函数式编程,说白就了就是在使用的地方定义函数,有的语言叫“闭包”,如果 lambda 函数没有传回值(例如 void ...
- FIREDAC调用中间件远程方法查询数据示例
服务端使用FDQUERY查询数据并返回TDATASET: function TServerMethods1.GetData(var sql: string): tdataset;begin qry.C ...
- Mac下的eclipse 4.6的tomcat插件安装正确姿势
最新版 eclipse 4.6 (Neon) tomcat 插件的安装, 解决tomcat插件tomcatPluginV331不能使用的问题. 1.打开最新版的 eclipse 4.6 (neon), ...
- opennebula 编译日志
[root@localhost opennebula-]# scons mysql=yes scons: Reading SConscript files ... Testing recipe: xm ...
- Display:Block
根据CSS规范的规定,每一个网页元素都有一个display属性,用于确定该元素的类型,每一个元素都有默认的display属性值,比如div元素,它的默认display属性值为“block”,成为“块级 ...
- 教你50招提升ASP.NET性能(十五):解决性能问题时不要低估UI的价值
(26)Don’t underestimate the value of the UI when tackling performance problems 招数26: 解决性能问题时不要低估UI的价 ...
- 使用Unity制作游戏关卡的教程(三)
转自:http://gamerboom.com/archives/75593 作者:Matthias Zarzecki 本文是“使用Unity制作<The Fork Of Truth>的关 ...
- 2015南阳CCPC H - Sudoku 暴力
H - Sudoku Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Yi Sima was one of the best cou ...
- psp开发------汉化插件
近期略微研究了下psp汉化,写了个汉化插件,在这记录下.聊以慰藉. 传统的汉化流程找码表,字库,破解什么这里不多讲,网上有教程.以下说下一种另类汉化方法.特别对于难以破解字库的游戏,当然这样的方法也有 ...