用了点离散化的处理, 然后二分一下就可以了。。。

Radar

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1928    Accepted Submission(s): 796

Problem Description
N cities of the Java Kingdom need to be covered by radars for being in a state of war. Since the kingdom has M radar stations but only K operators, we can at most operate K radars. All radars have the same circular coverage with a radius of R. Our goal is to minimize R while covering the entire city with no more than K radars.
Input
The input consists of several test cases. The first line of the input consists of an integer T, indicating the number of test cases. The first line of each test case consists of 3 integers: N, M, K, representing the number of cities, the number of radar stations and the number of operators. Each of the following N lines consists of the coordinate of a city. 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
Output
For each test case, output the radius on a single line, rounded to six fractional digits.
Sample Input
1 3 3 2 3 4 3 1 5 4 1 1 2 2 3 3
Sample Output
2.236068
Source
The 4th Baidu Cup final
Recommend
lcy
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <iostream>
using namespace std;
#define N 10000
#define INF 0x3fffffff
struct node
{double x,y;
}gn[55],gm[55];int n,m,k;
int U[N],D[N],R[N],L[N],num[N],H[N],col[N],line[N];
int head,id,mi;
int  nn,mm;
double g[N];double cal(node t,node t1)
{return sqrt( (t.x-t1.x)*(t.x-t1.x)+(t.y-t1.y)*(t.y-t1.y) );
}void prepare()
{for(int i=0;i<=mm;i++){num[i]=0;U[i]=i;D[i]=i;R[i]=i+1;L[i+1]=i;}R[mm]=0;L[0]=mm;memset(H,-1,sizeof(H));
}void link(int tn,int tm)
{id++;num[line[id]=tm]++;col[id]=tn;U[D[tm]]=id;D[id]=D[tm];U[id]=tm;D[tm]=id;if( H[tn]<0 ) H[tn]=R[id]=L[id]=id;else{L[R[H[tn]]]=id;R[id]=R[H[tn]];L[id]=H[tn];R[H[tn]]=id;}
}int h()
{int mark[66];memset(mark,0,sizeof(mark));int sum=0;for(int i=R[head];i!=head;i=R[i]){if(mark[i]==0){sum++;mark[i]=1;for(int j=D[i];j!=i;j=D[j])for(int k=R[j];k!=j;k=R[k])mark[ line[k] ]=1;}}return sum;
}void remove(int s)
{for(int i=D[s];i!=s;i=D[i]){R[L[i]]=R[i];L[R[i]]=L[i];}
}void resume(int s)
{for(int i=U[s];i!=s;i=U[i])R[L[i]]=L[R[i]]=i;
}void dfs(int s)
{if(s+h()>=mi) return ;if(R[head]==head){mi=s;return ;}int tmi=INF,tu;for(int i=R[head];i!=head;i=R[i]){if(num[i]<tmi){tmi=num[i];tu=i;}}for(int i=D[tu];i!=tu;i=D[i]){remove(i);for(int j=R[i];j!=i;j=R[j])remove(j);dfs(s+1);for(int j=L[i];j!=i;j=L[j])resume(j);resume(i);}
}int DLX(double key)
{head=0;mm=n;nn=1;prepare();id=mm;for(int i=1;i<=m;i++){int flag=0;for(int j=1;j<=n;j++){if(cal(gn[j],gm[i]) <= key){flag=1;link(i,j);}}if(flag==1) nn++;}mi=INF;dfs(0);if(mi<=k)return 1;else return 0;
}int main()
{int T;scanf("%d",&T);while(T--){scanf("%d%d%d",&n,&m,&k);for(int i=1;i<=n;i++){scanf("%lf%lf",&gn[i].x,&gn[i].y);}for(int i=1;i<=m;i++){scanf("%lf%lf",&gm[i].x,&gm[i].y);}int cnt=0;for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){g[cnt++]=cal(gn[i],gm[j]);}sort(g,g+cnt);int b=0,d=cnt-1;while(b<d){int mid=(b+d)/2; // 因为是选d 所以要使d绝对不能等于mid if( DLX(g[mid])==1 ){d=mid; // 要抓住关键的是找最大还最小, 要让=mid 的哪个尽量与mid不相等
            }else{b=mid+1;}}double ans;ans=(g[b]*10000000+0.5)/10000000;printf("%.6lf\n",g[b]);}return 0;
}

hdu 2295(DLX+二分)相关推荐

  1. hdu 2295 Radar(二分+DLX)

    题目链接:hdu 2295 Radar 题意: 给你n个城市,m个雷达,现在最多用K个雷达,求最小半径覆盖全部的城市. 题解: 二分半径套一个DLX就行.网上随便找的一个板子 1 #include&l ...

  2. hdu 2295 Radar DLX 重复覆盖问题

    http://acm.hdu.edu.cn/showproblem.php?pid=229 题意: 一个国家有n个城市,m个雷达,我们同时操作的雷达数最多为k,给出城市与国家的坐标,求小于等于k的操作 ...

  3. hdu 2295 Radar 重复覆盖+二分

    题目链接 给m个雷达, n个城市, 以及每个城市的坐标, m个雷达里只能使用k个, 在k个雷达包围所有城市的前提下, 求最小半径. 先求出每个雷达到所有城市的距离, 然后二分半径, 如果距离小于二分的 ...

  4. hdu 3641 数论 二分求符合条件的最小值数学杂题

    http://acm.hdu.edu.cn/showproblem.php?pid=3641 学到: 1.二分求符合条件的最小值 /*================================= ...

  5. hdu 1281棋盘游戏(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281 Problem Description 小希和Gardon在玩一个游戏:对一个N*M的棋盘,在格 ...

  6. hdu 4190(二分)

    思路:二分答案每次验证一下是否可行. 代码如下: 1 /************************************************** 2 * Author : xiaohao ...

  7. hdu 3585(二分+最大团)

    如果对团的知识不够了解的可以看看牛人的 http://www.cnblogs.com/pushing-my-way/archive/2012/08/08/2627993.html 题意:有n个点求最远 ...

  8. hdu 4768 Flyer 二分

    http://acm.hdu.edu.cn/showproblem.php?pid=4768 思路: 解题关键是奇数+偶数=奇数,然后我们就是枚举奇数位置(奇数为就一个或者0个),然后计算左边的和是否 ...

  9. hdu 5101(二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5101 题意:给定一些集合,选择两个来自不同集合的数,加和大于k,问有多少种选择方案 答案=从所有数中选 ...

  10. hdu 5188 dfs+二分

    get了很多新技能 当时想到了用dfs,但是排序用的是限制时间排序,一直没搞出来. 正解: 二分用时,dfs判断,为了顺利进行做题,需要按照做题开始时间排序 还可以用dp 题意: 作为史上最强的刷子之 ...

最新文章

  1. java伪装成mysql从节点_开发时java项目启动时需要连mysql等,有没有什么工具可以mock连接使得启动顺利不报错?...
  2. ios 获得通讯录中联系人的所有属性 亲测,可行 兼容io6 和 ios 7
  3. Web.Config介绍
  4. springCloud - 第7篇 - 配置文件管理中心 ( SpringCloud Config )
  5. 如何自定义一个starter组件
  6. python装饰品 后端_python装饰器
  7. opencv不能读取MP4格式文件
  8. 利用DELPHI开发完成例程(1)
  9. 0.618 与 1.414
  10. centos6 ab性能测试web服务器
  11. 专业的CMMI3认证咨询公司告诉你从CMMI3升到CMMI5级有哪些优势?
  12. 我想外包开发一个预约类小程序,大概需要多少钱?
  13. 前端人不可错过的低代码神器,告别切图,一键成稿啦!
  14. 入门爬虫二三记(一):爬取酷狗音乐榜单Top500
  15. 一些相似单词的区别之处
  16. uiautomatorviewer无法启动
  17. EasyGBS主子码流都为H.265时,切换出现花屏如何解决?
  18. 业内人士给龙年买房人的15条忠告 看到的有福了
  19. 一文详解知识图谱关键技术与应用 | 公开课笔记
  20. 笔记本外接显示器提示输入不支援

热门文章

  1. dsp 有fft程序吗_Python 中 FFT 快速傅里叶分析
  2. R实践 第二篇:创建数据集
  3. (六)授权(下):自定义permission
  4. python走起之第十三话
  5. Redis集群方案介绍
  6. 分享磨砺营威哥讲解-Android开发过程中内存优化的几点总结
  7. Tomcat默认端口,关闭不必要的安全隐患
  8. Using Java in Debian
  9. 概率论与数理统计 重点篇
  10. origin函数绘图_资料|史上最全10套Origin科研必备绘图教学,无需代码