maximum shortest distance
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 |
|
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的更多相关文章
- 【二分+最大团】【HDU3585】【maximum shortest distance】
题目大意 在N个点钟 选出K个点 使得这K个点间的最小距离最大 二分距离,然后如果两点间距离小于它的边当做不存在,求出最大团,如果最大团>=K,向上缩小区间 < K , 向下缩小区间 ...
- Maximum Shortest Distance 最大团 二分答案 HDU 3585
题意:给出n个点 要求取k个点 这k个点中 距离最小的两个点要求距离最大 拿到手看不出是最大团 也看不出是二分答案(第一次用) 因为答案必然存在 一定有一个最值 所以用二分答案来做 最大距 ...
- [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 ...
- [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 ...
- PAT1046: Shortest Distance
1046. Shortest Distance (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...
- [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 ...
- 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 ...
- [LeetCode] Shortest Distance to a Character 到字符的最短距离
Given a string S and a character C, return an array of integers representing the shortest distance f ...
- PAT A1046 Shortest Distance
PAT A1046 Shortest Distance 标签(空格分隔): PAT TIPS: 最后一个数据点可能会超时 #include <cstdio> #include <al ...
随机推荐
- Codeforce 854 A. Fraction
A. Fraction time limit per test 1 second memory limit per test 512 megabytes input standard input ou ...
- ThinkPHP中:使用递归写node_merge()函数
需求描述: 现有一个节点集合 可以视为一个二维数组 array(5) { [0] => array(4) { ["id"] => string(1) "1&q ...
- 修改host可以上的一些网站
打开路径 C:\Windows\System32\drivers\etc 博客园 223.6.248.220 www.cnblogs.com github 192.30.253.112 github. ...
- jvm系列(四):jvm知识点总结
原文链接:http://www.cnblogs.com/ityouknow/p/6482464.html jvm 总体梳理 jvm体系总体分四大块: 类的加载机制 jvm内存结构 GC算法 垃圾回收 ...
- 【原】Spark 编程指南
尊重原创,注重版权,转贴请注明原文地址:http://www.cnblogs.com/vincent-hv/p/3322966.html 1.配置程序使用资源: System.setPropert ...
- Fix “Could not flush the DNS Resolver Cache: Function failed during execution” When Flushing DNS
ipconfig /flushdns It is possible that you’re getting an error message “Could not flush the DNS Reso ...
- svn服务端安装、权限修改以及客户端的使用
2017-10-1016:10:2 svn服务端安装.权限修改以及客户端的使用 svn服务端.客户端.汉化包下载 http://pan.baidu.com/s/1c1Ogj2C 1.安装服务器端程序( ...
- winwebmail设置能用foxmail收发邮件
域名解析注意 1.首先做A记录解析: 主机名处:输入 mail IP地址处:输入IP地址 2.做MX记录: 主机名处: 大都保持空输入,什么也不用输入 TTL:默认就可以了,不需要改动 优先级:一 ...
- JavaScript设计模式--桥梁模式--XHR连接队列
针对该模式的例子现在不是很理解,写下来慢慢熟悉. 们要构建一个队列,队列里存放了很多ajax请求,使用队列(queue)主要是因为要确保先加入的请求先被处理.任何时候,我们可以暂停请求.删除请求.重试 ...
- JS实现时钟特效
<!DOCTYPE html><html><head lang="en"><meta charset="UTF-8"& ...