maximum shortest distance

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 60 Accepted Submission(s): 27
 
Problem Description
There are n points in the plane. Your task is to pick k points (k>=2), and make the closest points in these k points as far as possible.
 
Input
For each case, the first line contains two integers n and k. The following n lines represent n points. Each contains two integers x and y. 2<=n<=50, 2<=k<=n, 0<=x,y<10000.
 
Output
For each case, output a line contains a real number with precision up to two decimal places.

 
Sample Input
3 2
0 0
10 0
0 20
 
Sample Output
22.36
 
Author
alpc50
 
Source
2010 ACM-ICPC Multi-University Training Contest(15)——Host by NUDT
 
Recommend
zhouzeyong
 
/*
题意:给出n个点,现在让你选k个点,这k个点中,最近的两个点的距离最大 初步思路:刚好做到最大团这里,转化成最大团问题,二分,用二分的距离建边,比这条边长的两点才连线 #wa了一发:为啥double等于的时候 用减法判断开1e-6就不对,1e-8就对
*/
#include<bits/stdc++.h>
#define eps 1e-8
using namespace std;
/***********************************最大团模板************************************/
struct MAX_CLIQUE {
static const int N=; bool G[N][N];//存储图
int n;//图的定点数
int Max[N];//保存每个节点为根节点搜索到的最大团的定点数
int Alt[N][N];//用来存储第i层的节点
int ans;//用来存储最大团的定点数 bool DFS(int cur, int tot) {//cur表示当前层数的顶点数 tot表示搜索到的当前层数
if(cur==) {//不能扩展了就停止
if(tot>ans) {
ans=tot;
return ;
}
return ;
}
for(int i=; i<cur; i++) {
if(cur-i+tot<=ans) return ;//剪枝如果子图的节点数 加上 所有的定点数加上当前的层数 小于 前面找到的最大团 int u=Alt[tot][i];
if(Max[u]+tot<=ans) return ; int nxt=;
for(int j=i+; j<cur; j++)
if(G[u][Alt[tot][j]])
Alt[tot+][nxt++]=Alt[tot][j]; if(DFS(nxt, tot+)) return ;
}
return ;
} int MaxClique(){
ans=, memset(Max, , sizeof Max);
for(int i=n-; i>=; i--) {
int cur=;
for(int j=i+; j<n; j++)
if(G[i][j])
Alt[][cur++]=j;
DFS(cur, );
Max[i]=ans;
}
return ans;
}
};
struct Point{
int x,y;
Point(){}
Point(int a,int b){
x=a;
y=b;
}
void input(){
scanf("%d%d",&x,&y);
}
double dis(Point b){
return sqrt((x-b.x)*(x-b.x)+(y-b.y)*(y-b.y));
}
};
MAX_CLIQUE fuck;
Point p[];
/***********************************最大团模板************************************/
void build(double r){
for(int i=;i<fuck.n;i++){
for(int j=;j<fuck.n;j++){
if(p[i].dis(p[j])-r>=eps)
fuck.G[i][j]=;
else fuck.G[i][j]=;
}
}
}
int k; int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d%d",&fuck.n,&k)!=EOF){
for(int i=;i<fuck.n;i++){
p[i].input();
}
double l=0.0,r=20000.0;
while(r-l>eps){
double m=(l+r)/2.0;
build(m);
if(fuck.MaxClique()>=k)//满足
l=m;
else r=m;
}
printf("%.2lf\n",l);
}
return ;
}

maximum shortest distance的更多相关文章

  1. 【二分+最大团】【HDU3585】【maximum shortest distance】

    题目大意 在N个点钟 选出K个点 使得这K个点间的最小距离最大 二分距离,然后如果两点间距离小于它的边当做不存在,求出最大团,如果最大团>=K,向上缩小区间 <  K  ,  向下缩小区间 ...

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

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

  3. [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 ...

  4. [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 ...

  5. PAT1046: Shortest Distance

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

  6. [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 ...

  7. 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 ...

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

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

  9. PAT A1046 Shortest Distance

    PAT A1046 Shortest Distance 标签(空格分隔): PAT TIPS: 最后一个数据点可能会超时 #include <cstdio> #include <al ...

随机推荐

  1. STM32获取DHT11温度传感器数据

    准备物件 STM32F103C8T6核心板 ST-LINK V2 DHT11 杜邦线若干 连接线 STM32F103C8T6芯片管脚图 管脚说明 连接仿真器 STM32 ST-LINKV2 VCC V ...

  2. servlet生成验证码

    1.因为朋友们都说现在很少用java自带的图形用户接口,所以小白的我就没去看awt和swing组件,因为要抓紧时间学习后面的,完了出去找工作,等以后再回来了解awt和swing:所以制作验证码的代码是 ...

  3. mybatis typehandler

    建立TypeHandler 我们知道java有java的数据类型,数据库有数据库的数据类型,那么我们在往数据库中插入数据的时候是如何把java类型当做数据库类型插入数据库,在从数据库读取数据的时候又是 ...

  4. 无限树Jquery插件zTree的使用方法

    其实Ztree官网已经有详细的API文档,一切以官网上的说明为准,我在此只是结合实践总结几条常用的ztree的功能特性. (ztree的语法结构是基于key-value的形式配置) 1:支持异步加载数 ...

  5. JavaScript高级(01)

    前端开发工具 1.1. WebStorm介绍和下载 l  介绍 WebStorm是JetBrains 推出的一款强大的HTML5编辑工具,拥有丰富的代码快速编辑,可以智能的补全代码.代码格式化.htm ...

  6. 应试记录2(没有转载标注,NOIP2016复赛过后自动删除)

    #include<stdio.h> #include<string.h> int main() { ]; memset(a, , sizeof(a)); ;i<=;i++ ...

  7. windows下PHP中Fatal error Call to undefined function curl_init()的解决方法

    参考官方解决方法:http://nz.php.net/manual/en/curl.installation.php 1.php安装目录下的ext文件夹下面是否有php_curl.dll文件,然后右键 ...

  8. python中strip函数的用法

    python中往往使用剥除函数strip()来对用户的输入进行清理.strip函数的最一般形式为: str.strip('序列') 其中,序列是一段字符串,该函数表示从头或者从尾部开始进行扫描,如果扫 ...

  9. git-分支使用方式

    需求场景:假如你看着教程完成了一个项目,但是感觉第一次代码掌握不牢,想要进行第二次代码练习--如果某某心里想我还有初始备份文件,我此时的心里独白是你的硬盘还够用吗o(╯□╰)o 1 创建一个新分支 - ...

  10. python urllib、urlparse、urllib2、cookielib

    1.urllib模块 1.urllib.urlopen(url[,data[,proxies]]) 打开一个url的方法,返回一个文件对象,然后可以进行类似文件对象的操作.本例试着打开google i ...