hdu 2295 dlx重复覆盖+二分答案
题目大意:
有一堆雷达工作站,安放至多k个人在这些工作站中,找到一个最小的雷达监控半径可以使k个工作人所在的雷达工作站覆盖所有城市
二分半径的答案,每次利用dlx的重复覆盖来判断这个答案是否正确
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <climits>
#include <cmath> using namespace std;
#define N 55
#define MAXNODE 3000
const double INF = 1e9;
const double eps = 1e-; int n,m,k; struct DLX{
int n,m,size;
int U[MAXNODE] , D[MAXNODE] , L[MAXNODE] , R[MAXNODE];
int col[MAXNODE] , row[MAXNODE];
int first[N] , cnt_col[N];
bool v[MAXNODE]; void init(int _n , int _m)
{
n = _n , m = _m , size = _m;
for(int i= ; i<=m ; i++){
U[i] = D[i] = i;
L[i] = i- , R[i] = i+;
col[i] = i , row[i] = ;
}
L[] = m , R[m] = ;
for(int i= ; i<=n ; i++) first[i] = -;
for(int i= ; i<=m ; i++) cnt_col[i] = ;
} void link(int r , int c)
{
++size;
U[D[c]] = size , D[size] = D[c];
U[size] = c , D[c] = size;
cnt_col[c]++; if(first[r]<) first[r] = L[size] = R[size] = size;
else{
R[size] = R[first[r]] , L[R[first[r]]] = size;
L[size] = first[r] , R[first[r]] = size;
}
row[size] = r , col[size] = c;
} 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;
}
} int f()
{
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 Dance(int d)
{
//这里k表示题目所给意思让我们至多在dlx中选择k行
if(d+f() > k) return false;
if(!R[]) return d<=k;
int st = R[];
for(int i=R[] ; i!= ; i=R[i])
if(cnt_col[st]>cnt_col[i]) st=i; for(int i=D[st] ; i!=st ; i=D[i]){
Remove(i);
for(int j=R[i] ; j!=i ; j=R[j]) Remove(j);
if(Dance(d+)) return true;
for(int j=L[i] ; j!=i ; j=L[j]) Resume(j);
Resume(i);
}
return false;
}
}dlx; struct Point{
double x,y;
}p1[N] , p2[N]; double getDis(int i , int j)
{
return sqrt((p1[i].x-p2[j].x)*(p1[i].x-p2[j].x)+(p1[i].y-p2[j].y)*(p1[i].y-p2[j].y));
} bool check(double mid)
{
dlx.init(m , n);
for(int i= ; i<=m ; i++){
for(int j=; j<=n ;j++){
if(getDis(j , i)<=mid) dlx.link(i,j);
}
}
return dlx.Dance();
} double bin_search()
{
double l= , r=INF;
while(r-l>eps){
double mid = (l+r)/;
if(check(mid)) r=mid;
else l=mid;
}
return r;
} int main()
{
// freopen("a.in" , "r" , stdin);
int T;
scanf("%d" , &T);
while(T--)
{
scanf("%d%d%d" , &n , &m , &k);
for(int i= ; i<=n ; i++)
scanf("%lf%lf" , &p1[i].x , &p1[i].y);
for(int i= ; i<=m ; i++)
scanf("%lf%lf" , &p2[i].x , &p2[i].y);
printf("%.6lf\n" , bin_search());
}
return ;
}
hdu 2295 dlx重复覆盖+二分答案的更多相关文章
- (中等) HDU 2295 , DLX+重复覆盖+二分。
Description N cities of the Java Kingdom need to be covered by radars for being in a state of war. S ...
- hdu 2295 Radar 重复覆盖+二分
题目链接 给m个雷达, n个城市, 以及每个城市的坐标, m个雷达里只能使用k个, 在k个雷达包围所有城市的前提下, 求最小半径. 先求出每个雷达到所有城市的距离, 然后二分半径, 如果距离小于二分的 ...
- HDU 2295 Radar 重复覆盖 DLX
题意: N个城市,M个雷达站,K个操作员,问雷达的半径至少为多大,才能覆盖所有城市.M个雷达中最多只能有K个同时工作. 思路: 二分雷达的半径,看每个雷达可以覆盖哪些城市,然后做重复覆盖,判断这个半径 ...
- hdu3656Fire station(DLX重复覆盖 + 二分)
题目请戳这里 题目大意:一个城市n个点,现在要建m个消防站,消防站建在给定的n个点中.求建m个消防站后,m个消防站要覆盖所有的n个点的覆盖半径最小. 题目分析:重复覆盖问题,DLX解决.不过要求覆盖半 ...
- (中等) HDU 3335 , DLX+重复覆盖。
Description As we know,the fzu AekdyCoin is famous of math,especially in the field of number theory. ...
- hdu2295(重复覆盖+二分)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2295 题意::一个国家有n个城市,有m个地方可以建造雷达,最多可以建K个雷达(K>=1 & ...
- hdu 2295 DLX
思路:裸的DLX重复覆盖 #include<set> #include<cmath> #include<queue> #include<cstdio> ...
- 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 ...
随机推荐
- 序列化pickle模块
1.pickle模块 pickle.dumps() 和pickle.loads() import pickle f = open('112.pkl','w') a = {'name':2,2:3,3: ...
- CF749D Leaving Auction
题目链接: http://codeforces.com/problemset/problem/749/D 题目大意: 一场拍卖会,共n个买家.这些买家共出价n次,有的买家可能一次都没有出价.每次出价用 ...
- 毕业设计:主界面(ViewPager + FragmentPagerAdapter)
一.主要思路 应用程序的主界面包含三个部分:顶部标题栏.底部标识栏和中间的内容部分.顶部标题栏内容基本不变,用于显示当前模块或者整个应用的名称:底部既能标识出当前Page,又能通过触发ImageBut ...
- Entity Framework + MySQL 使用笔记
添加: using (var edm = new NorthwindEntities()) { Customers c = ", Region = "天府广场", Con ...
- ubuntu下安装redis扩展
采用源码编译安装 下载 下载redis源码包到本地一个临时目录 git clone https://github.com/phpredis/phpredis.git 移动文件到合适目录 mv phpr ...
- HYSBZ 1208 宠物收养所 (Splay树)
题意:一家宠物收养所负责处理领养者与遗弃宠物业务,有人来领宠物,则领一只最理想的.若没有宠物了,领养者们就得等到宠物来,宠物一来立刻送给其中一个等待者.如果有两个理想的选择,则选择那个值较小的.收养所 ...
- powerDesigner 把name项添加到注释(comment),完美方案!
第一次写博客,分享一点经验吧,平时大家用powerDesigner的时候,pd是不会把name项默认添加到comment的,所以生成的数据库表里面也没有中文字段的注释. 我在网上查了一下.有解决方案了 ...
- tomcat 安全配置文档
1.配置文档中使用$CATALINA_HOME变量声明为tomcat的安装目录并明确写出了tomcat的配置文件路径,此路径为测试环境的路径,线上系统对应配置文件的路径可能不一样,在进行相关配置时,应 ...
- SqlSugar直接执行Sql
参考:http://www.codeisbug.com/Doc/8/1132 我的思路: 1.数据库中写好sql 2.用SqlSugar直接执行sql,获取DataTable的数据 3.DataTab ...
- thinkphp5实现文件上传
原理:通过form表单的enctype = "multipart / form-data"属性将文件临时放在htdocs文件夹的tmp目录下,再通过后台的程序将文件保存在自己设定的 ...