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 ;
}

最新文章

  1. css3相册图片3D旋转展示特效
  2. Delphi以及三方控件的源代码规模
  3. 关于JAVA的数据转换总结
  4. PL/SQL Developer中文版下载以及使用图解(绿色版)
  5. 《JavaScript语言精粹》之函数化
  6. ADF_ADF Faces系列2_使用JSF开发基于Ajax的用户界面:ADF Faces富客户端组件简介(Part2)
  7. Data Flow -&gt;&gt; Pivot
  8. Jquery 弹出新窗体
  9. 将Uploads文件夹移到其它地方
  10. c缺陷与陷阱笔记-第六章 预处理器
  11. PHP 概述 特点 基础语法
  12. C# DES对称加密解密
  13. DotNetZip 压缩下载
  14. 分布式内存网格Hazelcast源码导读
  15. Oracle解决Ora-01653无法扩展表空间问题
  16. Qt class
  17. laravel进行单元测试的时候如何模拟数据库以及mockery的调用
  18. 【转】CEF3加载网页---多字节字符集和UNICODE字符集
  19. Windows AD域管理软件是什么?
  20. go语言之进阶篇数组越界导致panic

热门文章

  1. GCD之死锁体会
  2. AngularJS–service(服务)
  3. 集群提交spark任务命令
  4. Redis缓存项目应用架构设计一
  5. C#程序员应该养成的程序性能优化写法
  6. Linux常见命令集锦
  7. ubuntu中运行python脚本
  8. Java基础语法(下篇)
  9. c++ 11 移动语义、std::move 左值、右值、将亡值、纯右值、右值引用
  10. 学习笔记之09小练习题(js:从小到大输出三个任意数,查成绩,相亲题,查体重,一元二次方程求根)