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 ...
随机推荐
- python基础之条件循环语句
前两篇说的是数据类型和数据运算,本篇来讲讲条件语句和循环语句. 0x00. 条件语句 条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. 可以通过下图来简单了解条件语 ...
- iOS蓝牙心得
1.获取蓝牙mac地址 因为安卓不能得到uuid,所以,在要同步的时候要将uuid转换成mac地址,下面是转换方法 [peripheral discoverServices:@[[CBUUID UUI ...
- iOS9.3越狱
转载:http://bbs.feng.com/read-htm-tid-10680439.html 首先是Windows英文版越狱的的教程 下载 Cydia Impactor 工具(用来安装越狱A ...
- SpringMVC——使用RequestDispatcher.include()和HttpServletResponseWrapper动态获取jsp输出内容
介绍本篇内容前,先抛出我遇到的问题或者说是需求!(精读阅读本篇可能花费您15分钟,略读需5分钟左右) 一:需求说明 有一个Controller有两个方法 第一个方法通过指定的路径和参数去渲染jsp内容 ...
- 使用C语言和Java分别实现冒泡排序和选择排序
经典排序算法--冒泡和选择排序法 Java实现冒泡排序 基本思想是,对相邻的元素进行两两比较,顺序相反则进行交换,这样,每一趟会将最小或最大的元素放到顶端,最终达到完全有序,首先看个动图: 我们要清楚 ...
- 关于el-dialog,我更推荐的用法
最近的项目里用上了vue和element-ui.vue这种轻量级渐进式框架的舒适自不必说,但一直困扰着我的,是如何方便又优雅的弹出模态dialog... 对于我这种在jquery出现之前就用docum ...
- every();some();filter();map();forEach()各自区别:
every();some();filter();map();forEach()各自区别: (1)every()方法:(返回值为boolean类型) 对数组每一项都执行测试函数,知道获得对指定的函数返回 ...
- Winform窗体间传递数据
public string passText { get { return textBox1.Text; } } //Form1中还有个按钮button1在其点击事件中有: private void ...
- AspectCore中的IoC容器和依赖注入
IOC模式和依赖注入是近年来非常流行的一种模式,相信大家都不陌生了,在Asp.Net Core中提供了依赖注入作为内置的基础设施,如果仍不熟悉依赖注入的读者,可以看看由我们翻译的Asp.Net Cor ...
- Linux 进程状态 概念 Process State Definition
From : http://www.linfo.org/process_state.html 进程状态是指在进程描述符中状态位的值. 进程,也可被称为任务,是指一个程序运行的实例. 一个进程描述符是一 ...