HDU 2295.Radar (DLX重复覆盖)
2分答案+DLX判断可行
不使用的估计函数的可重复覆盖的搜索树将十分庞大
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std; #define FOR(i,A,s) for(int i = A[s]; i != s; i = A[i])
#define exp 1e-8 const int MAX = , MAXR = , MAXC = ;
int n, m, k, t; struct DLX {
int n, Size;//Size为尾指针,真正大小
int row[MAX], col[MAX];//记录每个点的行列
int U[MAX], D[MAX], R[MAX], L[MAX]; //4个链表
int S[MAXC];//每列1的个数
int ncnt, ans[MAXR];
void init (int n) {
this->n = n;
//增加n+1个辅助链表,从0到n
for (int i = ; i <= n; i++)
U[i] = D[i] = i, L[i] = i - , R[i] = i + ;
R[n] = , L[] = n; //头尾相接
Size = n + ;
memset (S, , sizeof S);
}
//逐行添加
void addRow (int r, int columns[]) {
int first = Size;
for (int i = ; i <= n ; i++) {
if (columns[i] == ) continue;
int c = i;
L[Size] = Size - , R[Size] = Size + ;
U[Size] = U[c], D[Size] = c;//插入第c列
D[U[c]] = Size, U[c] = Size; //注意顺序!!!
row[Size] = r, col[Size] = c;
Size++, S[c]++;
}
if (Size > first)
R[Size - ] = first, L[first] = Size - ; //头尾相接
}
void Remove (int c) {
//精确覆盖
// L[R[c]] = L[c], R[L[c]] = R[c];
// FOR (i, D, c)
// FOR (j, R, i)
// U[D[j]] = U[j], D[U[j]] = D[j], --S[col[j]];
//重复覆盖
for (int i = D[c]; i != c; i = D[i])
L[R[i]] = L[i], R[L[i]] = R[i];
}
void Restore (int c) {
// FOR (i, U, c)
// FOR (j, L, i)
// ++S[col[j]], U[D[j]] = j, D[U[j]] = j;
// L[R[c]] = c, R[L[c]] = c;
//重复覆盖
for (int i = U[c]; i != c; i = U[i])
L[R[i]] = R[L[i]] = i;
}
bool v[MAX];
int ff()
{
int ret = ;
for (int c = R[]; c != ; c = R[c]) v[c] = true;
for (int c = R[]; c != ; c = R[c])
if (v[c])
{
ret++;
v[c] = false;
for (int i = D[c]; i != c; i = D[i])
for (int j = R[i]; j != i; j = R[j])
v[col[j]] = false;
}
return ret;
}
bool dfs (int d) {
if (d + ff() > k) return ;
if (R[] == ) {
ncnt = d;
return d <= k;
}
int c = R[];
for (int i = R[]; i != ; i = R[i])
if (S[i] < S[c])
c = i;
//Remove (c);//精确覆盖
FOR (i, D, c) {
Remove (i);//重复覆盖
ans[d] = row[i];
//FOR (j, R, i) Remove (col[j]);
FOR (j, R, i) Remove (j);
if (dfs (d + ) ) return ;
//FOR (j, L, i) Restore (col[j]);
FOR (j, L, i) Restore (j);
Restore (i);//重复覆盖
}
//Restore (c);//精确覆盖
return ;
}
bool solve (vector<int> &v) {
v.clear();
if (!dfs () ) return ;
for (int i = ; i < ncnt; i++) v.push_back (ans[i]);
return ;
}
} f;
struct node {
int x, y;
} g[], Ra[];
int columns[][];
double dis[][];
inline double getdis (node a, node b) {
return sqrt (double ( (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) ) );
}
bool make (double mid) {
f.init (n);
for (int i = ; i <= m; i++)
for (int j = ; j <= n; j++)
columns[i][j] = dis[i][j] <= mid;
for (int i = ; i <= m; i++)
f.addRow (i, columns[i]);
return f.dfs ();
}
int main() {
scanf ("%d", &t);
while (t--) {
scanf ("%d %d %d", &n, &m, &k);
for (int i = ; i <= n; i++)
scanf ("%d %d", &g[i].x, &g[i].y);
for (int i = ; i <= m; i++)
scanf ("%d %d", &Ra[i].x, &Ra[i].y);
double l = 1e9, r = ;
for (int i = ; i <= m; i++)
for (int j = ; j <= n; j++) {
dis[i][j] = getdis (Ra[i], g[j]);
l = min (dis[i][j], l), r = max (r, dis[i][j]);
}
double ans = -;
while (r - l > 1e-) {
double mid = (r + l) / .;
if (make (mid) ) {
ans = mid;
r = mid - exp;
}
else
l = mid + exp;
}
printf ("%.6f\n", ans);
}
return ;
}
HDU 2295.Radar (DLX重复覆盖)的更多相关文章
- HDU 2295 Radar (重复覆盖)
Radar Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 2295 Radar (DLX + 二分)
Radar Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- [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 ...
- HDU 2295 Radar 重复覆盖 DLX
题意: N个城市,M个雷达站,K个操作员,问雷达的半径至少为多大,才能覆盖所有城市.M个雷达中最多只能有K个同时工作. 思路: 二分雷达的半径,看每个雷达可以覆盖哪些城市,然后做重复覆盖,判断这个半径 ...
- HDU 2295 Radar (二分 + Dancing Links 重复覆盖模型 )
以下转自 这里 : 最小支配集问题:二分枚举最小距离,判断可行性.可行性即重复覆盖模型,DLX解之. A*的启发函数: 对当前矩阵来说,选择一个未被控制的列,很明显该列最少需要1个行来控制,所以ans ...
- hdu 2295 dlx重复覆盖+二分答案
题目大意: 有一堆雷达工作站,安放至多k个人在这些工作站中,找到一个最小的雷达监控半径可以使k个工作人所在的雷达工作站覆盖所有城市 二分半径的答案,每次利用dlx的重复覆盖来判断这个答案是否正确 #i ...
- HDU 2295 Radar dancing links 重复覆盖
就是dancing links 求最小支配集,重复覆盖 精确覆盖时:每次缓存数据的时候,既删除行又删除列(这里的删除列,只是删除表头) 重复覆盖的时候:只删除列,因为可以重复覆盖 然后重复覆盖有一个估 ...
- HDU 5046 Airport【DLX重复覆盖】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5046 题意: 给定n个城市的坐标,要在城市中建k个飞机场,使城市距离最近的飞机场的最长距离最小,求这 ...
- (中等) HDU 3335 , DLX+重复覆盖。
Description As we know,the fzu AekdyCoin is famous of math,especially in the field of number theory. ...
随机推荐
- Jacob - Outlook
import com.jacob.activeX.ActiveXComponent; import com.jacob.com.Dispatch; public class Util { public ...
- java基础(十三)常用类总结(三)
这里有我之前上课总结的一些知识点以及代码大部分是老师讲的笔记 个人认为是非常好的,,也是比较经典的内容,真诚的希望这些对于那些想学习的人有所帮助! 由于代码是分模块的上传非常的不便.也比较多,讲的也是 ...
- 宁波Uber优步司机奖励政策(1月18日~1月24日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- m版页面判断安卓与ios系统
安卓系统和ios系统,在做app里面嵌入m版时,有时候会发现,ios上面的那个电池状态栏不占位置,但是安卓的状态栏占位,所以需要区分系统样式单独处理一下! var sUserAgent=navigat ...
- Javascript诞生与历史
基本常识 Brendan Eich在1995年4月入职Netscape Communications Corporation(网景通信公司).并于1995年5月用10天时间发明了Javascript. ...
- PPT扁平化手册 2
- Light OJ 1114 Easily Readable 字典树
题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...
- C# 该行已经属于还有一个表 的解决方法
产生错误的代码: DataTable dtContract_src = Oper.GetDataTable("select * from T_Contract where ProjectID ...
- linux 同步备份 rsyncd 相关设置
17:25 2013/10/18------------------ rsync linux 同步备份服务器 配置vi /etc/rsyncd.conf 配置文件 /usr/bin/rsync --d ...
- 常用Content-type汇总
Content-Type,内容类型,用于定义网络文件的类型和网页的编码,决定浏览器将以什么形式.什么编码读取这个文件.这里汇总一下常用的,所有资料来源于网络,未经测试: 文件后缀 处理方式 .* ...