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. centOS7服务管理与启动流程

    centOS7服务管理与启动流程 centOS7启动流程 systemd简介 unit对象 unit类型 特性 service unit文件格式 service unit file文件通常由三部分组成 ...

  2. Dijkstra堆优化学习

    最短路径例题 今天特地学习了Dijkstra的堆优化(主要是慕名已久). 我们需要一个堆来记录[编号,到编号这个点的最短路径值(当然只是当前的)] 与原来的Dijkstra操作基本一致,主要有以下几点 ...

  3. 《MATLAB从入门到放弃》二维曲线和图形绘制基础(一): 什么是图形对象和句柄 ?

    图形对象 一个图形包含了不同的对象 图形包括 核心对象和绘制对象 .  核心对象 线条对象 : line 文本对象 : text 矩形对象 : rectangle 补丁对象 : patch 图像对象  ...

  4. [js高手之路] html5 canvas系列教程 - 状态详解(save与restore)

    本文内容与路径([js高手之路] html5 canvas系列教程 - 开始路径beginPath与关闭路径closePath详解)是canvas中比较重要的概念.掌握理解他们是做出复杂canvas动 ...

  5. textarea文本域值中含有大量\t\n问题

    最近在发现了一个问题,很是头疼,textarea值中有大量的制表符,尝试了很多办法,最终找到了解决办法,希望能帮到同样有此困扰的你. <textarea> <c:out value= ...

  6. java集合系列——List集合之LinkedList介绍(三)

    1. LinkedList的简介 JDK 1.7 LinkedList是基于链表实现的,从源码可以看出是一个双向链表.除了当做链表使用外,它也可以被当作堆栈.队列或双端队列进行操作.不是线程安全的,继 ...

  7. "svn: E155010: 提交失败"问题解决

    习惯于通过命令行操作svn,今天如往常一样提交代码: AnnytekiMacBook-Air:weiyibao Anny$ svn ci -m "code" 居然报错,如下: sv ...

  8. String Problem hdu 3374 最小表示法加KMP的next数组

    String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  9. CentOS7 + Nginx1.13.5 + PHP7.1.10 + MySQL5.7.19 源码编译安装

    一.安装Nginx 1.安装依赖扩展 # yum -y install wget openssl* gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng ...

  10. java递归的应用和实例

    使用计算机计算组合数: 1.使用组合数公式利用n!来计算 设计思想 (1)首先解决求n!的函数 (2)再结合组合数公式,求组合数 程序流程图 源程序代码 package Zuote; import j ...