题目大意

在N个点钟 选出K个点 使得这K个点间的最小距离最大

二分距离,然后如果两点间距离小于它的边当做不存在,求出最大团,如果最大团>=K,向上缩小区间

<  K  ,  向下缩小区间

OK~

#include<stdio.h>
#include<math.h>
#include<iostream>
#define eps 1e-7
using namespace std; int n,k,vis[55],tmax,dp[55],ji;
int locat[55][2],map[55][55];
double dis[55][55],distan[2000]; int cmp(const void *a,const void*b)
{
return *(double *)a>*(double *)b?1:-1;
} void build(int mid)
{
int i,f;
for(i=1;i<=n;i++)
{
for(f=1;f<=n;f++)
{
if(dis[i][f] >= distan[mid]-eps)
{
map[i][f]=1;
}
else
{
map[i][f]=0;
}
}
map[i][i]=0;
}
} void dfs(int id,int cnt)
{
int tvis[55],i,f,able=0;
for(i=id+1;i<=n;i++)
{
if(1 == vis[i])
{
able++;
}
}
if(0 == able)
{
tmax=max(tmax,cnt);
}
if(cnt + able <= tmax)
{
return ;
}
for(i=1;i<=n;i++)
{
tvis[i]=vis[i];
}
for(i=id+1;i<=n;i++)
{
if(0 == tvis[i])
{
continue;
}
if(cnt +dp[i] <= tmax)
{
continue;
}
for(f=id+1;f<=n;f++)
{
vis[f]=tvis[f]&map[i][f];
}
dfs(i,cnt+1);
}
} int max_clique()
{
int i,f;
tmax=1;
dp[n]=1;
for(i=n-1;i>=1;i--)
{
for(f=1;f<=n;f++)
{
vis[f]=map[i][f];
}
dfs(i,1);
dp[i]=tmax;
if(n == tmax)
{
return tmax;
}
}
return tmax;
} double bs()
{
int l=0,r=ji,mid;
while(l != r-1)
{
mid=(l+r)>>1;
build(mid);
if(k <= max_clique())
{
l=mid;
}
else
{
r=mid;
}
}
return distan[l];
} int main()
{
int i,f,g,sum;
while(scanf("%d%d",&n,&k)!=EOF)
{
ji=0;
for(i=1;i<=n;i++)
{
scanf("%d%d",&locat[i][0],&locat[i][1]);
}
for(i=1;i<=n;i++)
{
for(f=1;f<=n;f++)
{
sum=0;
for(g=0;g<2;g++)
{
sum+=(locat[i][g]-locat[f][g])*((locat[i][g]-locat[f][g]));
}
dis[i][f]=sqrt((double)sum);
if(i > f)
{
distan[ji]=dis[i][f];
ji++;
}
}
}
qsort(distan,ji,sizeof(distan[0]),cmp);
printf("%.2lf\n",bs());
}
return 0;
}

【二分+最大团】【HDU3585】【maximum shortest distance】的更多相关文章

  1. maximum shortest distance

    maximum shortest distance Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...

  2. Maximum Shortest Distance 最大团 二分答案 HDU 3585

    题意:给出n个点   要求取k个点  这k个点中  距离最小的两个点要求距离最大 拿到手看不出是最大团  也看不出是二分答案(第一次用) 因为答案必然存在 一定有一个最值  所以用二分答案来做 最大距 ...

  3. [LeetCode] Shortest Distance to a Character 到字符的最短距离

    Given a string S and a character C, return an array of integers representing the shortest distance f ...

  4. 【LeetCode】1182. Shortest Distance to Target Color 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典+二分查找 日期 题目地址:https://lee ...

  5. [CareerCup] 18.5 Shortest Distance between Two Words 两单词间的最短距离

    18.5 You have a large text file containing words. Given any two words, find the shortest distance (i ...

  6. [Locked] Shortest Distance from All Buildings

    Shortest Distance from All Buildings You want to build a house on an empty land which reaches all bu ...

  7. PAT1046: Shortest Distance

    1046. Shortest Distance (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...

  8. [Swift]LeetCode821. 字符的最短距离 | Shortest Distance to a Character

    Given a string S and a character C, return an array of integers representing the shortest distance f ...

  9. LeetCode 613. Shortest Distance in a Line

    Table point holds the x coordinate of some points on x-axis in a plane, which are all integers. Writ ...

随机推荐

  1. hdu 5491 The Next(暴力枚举)

    Problem Description Let L denote the number of 1s in integer D’s binary representation. Given two in ...

  2. 利用FreeMarker静态化网页

    1.介绍-FreeMarker是什么 模板引擎:一种基于模板的.用来生成输出文本的通用工具 基于Java的开发包和类库 2.介绍-FreeMarker能做什么 MVC框架中的View层组件 Html页 ...

  3. Eddy's picture(prime+克鲁斯卡尔)

    Eddy's picture Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tota ...

  4. 高效CSS書寫規範及CSS兼容性

    一.選擇器針對性說明 某一元素的多个规则集中,选择器的针对性越高,该规则集的权重也就越高.针对性相同的,后出现的规则集的权重更高. * {} /* a=0 b=0 c=0 d=0 -> spec ...

  5. 从决策树学习谈到贝叶斯分类算法、EM、HMM

    从决策树学习谈到贝叶斯分类算法.EM.HMM                (Machine Learning & Recommend Search交流新群:172114338) 引言 log ...

  6. Eclipse SVN插件的帐号、password改动

    问题描写叙述: Eclipse的SVN插件Subclipse做得非常好,在svn操作方面提供了非常强大丰富的功能.但到眼下为止,该插件对svn用户的概念极为淡薄,不但不能方便地切换用户,并且一旦用户的 ...

  7. CSDN-Markdown语法集锦

    前言: 使用Markdown近一个来月.越来越认为不舒爽. 改字体.改字号.改颜色.改样式,全不会!想加个数学公式.得,仅仅会截图.把图片传上去了还不会控制大小.也不会控制文字与图片的排版,写出来的博 ...

  8. 【分割平面,分割空间类题】【HDU1290 HDU2050】

    HDU 2050 折线分割平面 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. Spring Annotation注解进行aop的学习

    使用Maven管理项目,pom文件为: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=" ...

  10. V - 不容易系列之(4)――考新郎(第二季水)

    Description          国庆期间,省城HZ刚刚举行了一场盛大的集体婚礼,为了使婚礼进行的丰富一些,司仪临时想出了有一个有意思的节目,叫做"考新郎",具体的操作是这 ...