思路:二分枚举建边,用DLX判断是否满足。

#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define clr(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mp make_pair
#define Maxn 20010
#define LL __int64
#define Abs(x) ((x)>0?(x):(-x))
#define lson(x) (x<<1)
#define rson(x) (x<<1|1)
#define inf 100000000
#define lowbit(x) (x&(-x))
#define Mod 1000000007
using namespace std;
int L[Maxn], R[Maxn], U[Maxn], D[Maxn];
int id, ans, S[Maxn], H[Maxn], C[Maxn];
int cnt,n,m;
double dis[][],edge[];
struct Point{
double x,y;
}p[Maxn];
double Dis(Point a,Point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool vis[];
void Link(int r, int c)
{
U[id] = c;
D[id] = D[c];
U[D[c]] = id;
D[c] = id;
if (H[r] < )
H[r] = L[id] = R[id] = id;
else
{
L[id] = H[r];
R[id] = R[H[r]];
L[R[H[r]]] = id;
R[H[r]] = id;
}
S[c]++;
C[id++] = c;
}
void Remove(int c)
{
int i;
for (i = D[c]; i != c; i = D[i])
{
L[R[i]] = L[i];
R[L[i]] = R[i];
}
}
void Resume(int c)
{
int i;
for (i = D[c]; i != c; i = D[i])
L[R[i]] = R[L[i]] = i;
}
int A()
{
int i, j, k, res;
memset(vis, false,sizeof(vis));
for (res = , i = R[]; i; i = R[i])
{
if (!vis[i])
{
res++;
for (j = D[i]; j != i; j = D[j])
{
for (k = R[j]; k != j; k = R[k]){
vis[C[k]] = true;
// cout<<i<<" "<<j<<" "<<k<<" "<<C[k]<<endl;
}
}
}
}
return res;
}
bool dfs (int step) {
if (step + A() > m) return false;
if (R[] == ) return true;
int temp = inf, id;
for (int i = R[]; i ; i = R[i]) {
if (S[i] < temp) {
temp = S[i];
id = i;
}
}
for (int i = D[id]; i != id; i = D[i]) {
Remove(i);
for (int j = R[i]; j != i; j = R[j]) {
Remove(j);
}
if (dfs(step + )) {
return true;
}
for (int j = L[i]; j != i; j = L[j]) {
Resume(j);
}
Resume(i);
}
return false;
}
void Init(int m)
{
int i;
for (i = ; i <= m; i++)
{
R[i] = i + ;
L[i + ] = i;
U[i] = D[i] = i;
S[i] = ;
}
R[m] = ;
id = m + ;
}
void build(int pos)
{
int i,j;
Init(n);
for(i=;i<=n;i++){
H[i]=-;
for(j=;j<=n;j++){
if(dis[i][j]<=edge[pos])
Link(i,j);
}
}
}
void solve()
{
int i,j;
int l,r,mid;
l=,r=cnt;
while(l<r){
mid=(l+r)>>;
build(mid);
if(dfs())
r=mid;
else
l=mid+;
}
printf("%.6lf\n",edge[l]);
}
int main()
{
int i,j,t;
//freopen("ttt.txt","r",stdin);
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
for(i=;i<=n;i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
}
cnt=;
for(i=;i<=n;i++){
for(j=i+;j<=n;j++){
dis[i][j]=dis[j][i]=Dis(p[i],p[j]);
edge[++cnt]=dis[i][j];
}
dis[i][i]=;
}
edge[++cnt]=;
sort(edge+,edge++cnt);
int num=;
for(i=;i<=cnt;i++){
if(edge[i]!=edge[num]){
edge[++num]=edge[i];
}
}
cnt=num;
solve();
}
return ;
}

hdu 3656 DLX的更多相关文章

  1. [DLX反复覆盖] hdu 3656 Fire station

    题意: N个点.再点上建M个消防站. 问消防站到每一个点的最大距离的最小是多少. 思路: DLX直接二分推断TLE了. 这时候一个非常巧妙的思路 我们求的距离一定是两个点之间的距离 因此我们把距离都求 ...

  2. HDU 3656 二分+dlx判定

    Fire station Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  3. HDU 3909 DLX

    http://blog.csdn.net/sr_19930829/article/details/39756513 http://www.kuangbin.net/archives/hdu4069-d ...

  4. hdu 3111 DLX解数独

    思路:裸的DLX解数独.关键是建图,感觉还不如写个dfs直接,DLX写这个的代码很烦. #include<set> #include<map> #include<cmat ...

  5. hdu 2295 DLX

    思路:裸的DLX重复覆盖 #include<set> #include<cmath> #include<queue> #include<cstdio> ...

  6. HDU 2828 DLX搜索

    Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  7. (中等) HDU 3335 , DLX+重复覆盖。

    Description As we know,the fzu AekdyCoin is famous of math,especially in the field of number theory. ...

  8. (中等) HDU 2295 , DLX+重复覆盖+二分。

    Description N cities of the Java Kingdom need to be covered by radars for being in a state of war. S ...

  9. hdu 2295 dlx重复覆盖+二分答案

    题目大意: 有一堆雷达工作站,安放至多k个人在这些工作站中,找到一个最小的雷达监控半径可以使k个工作人所在的雷达工作站覆盖所有城市 二分半径的答案,每次利用dlx的重复覆盖来判断这个答案是否正确 #i ...

随机推荐

  1. JPBM4.4基础及数据库说明

    JPBM4.4基础及数据库说明 对jBPM4.4数据库的几张表简单介绍: A.资源库和运行时表结构 JBPM4_DEPLOYMENT   流程定义表                           ...

  2. 如何自学Java

    转自:http://www.360doc.com/content/12/0624/19/5856897_220191533.shtml   JAVA自学之路 JAVA自学之路 一:学会选择 为了就业, ...

  3. 记一次Time-Wait导致的问题

    去年(2014年)公司决定服务框架改用Finagle(后续文章详细介绍),but 公司业务系统大部分是C#写的,然后 finagle只提供了 scala/java 的Client 于是 只能自己动手丰 ...

  4. jquery.validate使用攻略

    主要分几部分 jquery.validate 基本用法 jquery.validate API说明 jquery.validate 自定义 jquery.validate 常见类型的验证代码 下载地址 ...

  5. linux C(hello world)最大公约数和最小公倍数

    # include <stdio.h> int main(void) { int x, y,temp; int r; printf("请输入两个正整数:\n"); sc ...

  6. volley开源库乱码问题总结(持续更新)

    之前Android开发一直用的是多层封装的Final框架.最近开始学习使用小巧的volley. 在使用该框架的过程中,出现了数次乱码问题,再次做以总结. 分别是返回数据乱码和提交参数乱码两个问题: 一 ...

  7. Android上的SQLLite性能分析

    也许有人还不知道,Android 是有一些内建的 类库支持 SQL Lite 数据库的操作.他提供了一个很好的方式在 Android 上组织少量的数据.不管怎样,在使用这些类库的时候有一些陷阱是需要注 ...

  8. 使用ajax和window.history.pushState无刷新改变页面内容和地址栏URL

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  9. [CoffeeScript] Level 4 Arrays, Objects, Iterations -- Ex

    Coffee on the Range Create an array with numbers 1 until 10 using the inclusive (two dot) range synt ...

  10. iOS开发——UI篇Swift篇&UISegmentedControl

    UISegmentedControl override func viewDidLoad() { super.viewDidLoad() titleLabel.text = titleString / ...