HDU 2295 Radar (重复覆盖的模板 即每列至少一个1)
来源:互联网 发布:诛仙数据互通查询 编辑:程序博客网 时间:2024/05/19 19:43
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2295
题目大意:有n个城市,m个雷达,k个人,然后给出n个城市和m个雷达站的坐标
现在要求选出k个雷达站,求出能覆盖所有城市的雷达最小半径
思路:相当于n个城市为列,m个雷达为行。要求每个城市至少没被一个雷达覆盖.
二分答案, 然后使用重复覆盖的Dancing Links模板进行判断,看使用K个能不能覆盖n个点
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;const int maxnode = 3000;const int MaxM = 55;const int MaxN = 55;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[MaxN]; int ands,ans[MaxN]; void init(int _n,int _m) { n = _n; m = _m; for(int i = 0;i <= m;i++) { S[i] = 0; U[i] = D[i] = i; L[i] = i-1; R[i] = i+1; } R[m] = 0; L[0] = m; size = m; for(int i = 1;i <= n;i++) H[i] = -1; } 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] < 0)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 v[maxnode]; int f() { int ret = 0; for(int c = R[0];c != 0;c = R[c])v[c] = true; for(int c = R[0];c != 0;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 Dance(int d) { if(d + f() > K)return false; if(R[0] == 0)return d <= K; int c = R[0]; for(int i = R[0];i != 0;i = R[i]) if(S[i] < S[c]) 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(Dance(d+1))return true; for(int j = L[i];j != i;j = L[j])resume(j); resume(i); } return false; }};DLX g;const double eps = 1e-8;struct Point{ int x,y; void input() { scanf("%d%d",&x,&y); }}city[MaxM],station[MaxN];double dis(Point a,Point b){ return sqrt((double)(a.x-b.x)*(a.x-b.x)+(double)(a.y-b.y)*(a.y-b.y));}int main(){ int T; int n,m; scanf("%d",&T); while(T--) { scanf("%d%d%d",&n,&m,&K); for(int i = 0;i < n;i++)city[i].input(); for(int i = 0;i < m;i++)station[i].input(); double l = 0, r = 1e8; while(r-l >= eps)//二分查找 { double mid = (l+r)/2; g.init(m,n); for(int i = 0;i < m;i++) for(int j = 0;j < n;j++) if(dis(station[i],city[j]) < mid - eps)//如果小于假设的距离的话 g.Link(i+1,j+1); if(g.Dance(0))r = mid-eps;//如果成立的 将r缩小查询 else l = mid+eps;//如果不成立的话 将l增大查询 } printf("%.6lf\n",l); } return 0;}
阅读全文
0 0
- HDU 2295 Radar (重复覆盖的模板 即每列至少一个1)
- HDU 2295 Radar(重复覆盖,DLX)
- HDU 2295 Radar(二分+重复覆盖)
- hdu 2295 Radar(重复覆盖问题)
- [ACM] HDU 2295 Radar (二分+DLX 重复覆盖)
- HDU 2295 Radar(DLX可重复覆盖)
- hdu 2295 Radar(Dancing Links重复覆盖)
- [ACM] HDU 2295 Radar (二分+DLX 重复覆盖)
- HDU 2295 Radar(重复覆盖|Dancing Links)
- HDU 2295 Radar (DLX可重复覆盖+二分)
- HDU 2295 Radar(二分+DLX重复覆盖)
- HDU 2295 Radar DLX重复覆盖
- hdu 2295 Radar(重复覆盖,二分+DLX)
- 【HDU】2295 Radar 二分+重复覆盖
- HDU 2295 Radar (二分+DLX,重复覆盖)
- HDU 2295 Radar DLX重复覆盖
- [HDU]2295 Radar 跳舞链 重复覆盖
- HDU 2295 Radar【二分+Dancing Links重复覆盖】
- Linux TNS-12541 TNS-12560 TNS-00511 NO LISTENER
- 387. First Unique Character in a String字母表数组的运动
- PAT乙级(Basic)题库---1008
- SVN如何断开和服务器的连接
- 前端构建工具gulpjs的使用介绍及技巧
- HDU 2295 Radar (重复覆盖的模板 即每列至少一个1)
- java 用redis如何处理电商平台,秒杀、抢购超卖
- JS实现无限加载瀑布流
- LuaView 初识
- oracle exp,imp
- Pandas Timedelta对象
- [leetcode]58. Length of Last Word@Java
- tomcat部署之王(包含Eclipse,MyEclipse,idea三种工具)
- linux挂载NAS