分治法

Sample Input
2
0 0
1 1
2
1 1
1 1
3
-1.5 0
0 0
0 1.5
0

Sample Output
0.71
0.00
0.75

 # include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <string>
# include <cmath>
# include <queue>
# include <list>
# define LL long long
using namespace std ; const double eps = 1e-;
const int MAXN = ;
const double INF = 1e20;
struct Point
{
double x,y;
}; double dist(Point a,Point b)
{
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
} Point p[MAXN];
Point tmpt[MAXN];
bool cmpxy(Point a,Point b)
{
if(a.x != b.x)return a.x < b.x;
else return a.y < b.y;
}
bool cmpy(Point a,Point b)
{
return a.y < b.y;
}
double Closest_Pair(int left,int right)
{
double d = INF;
if(left == right)return d;
if(left + == right)
return dist(p[left],p[right]);
int mid = (left+right)/;
double d1 = Closest_Pair(left,mid);
double d2 = Closest_Pair(mid+,right);
d = min(d1,d2);
int k = ;
for(int i = left;i <= right;i++)
{
if(fabs(p[mid].x - p[i].x) <= d)
tmpt[k++] = p[i];
}
sort(tmpt,tmpt+k,cmpy);
for(int i = ;i <k;i++)
{
for(int j = i+;j < k && tmpt[j].y - tmpt[i].y < d;j++)
{
d = min(d,dist(tmpt[i],tmpt[j]));
}
}
return d;
} int main()
{
//freopen("in.txt","r",stdin) ;
int n;
while(scanf("%d",&n)== && n)
{
for(int i = ;i < n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
sort(p,p+n,cmpxy);
printf("%.2lf\n",Closest_Pair(,n-)/);
}
return ;
}

hdu 1007 N个点中输出2点的最小距离的一半的更多相关文章

  1. HDU 1007 Quoit Design(二分+浮点数精度控制)

    Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  2. HDU 3065 病毒侵袭持续中

    HDU 3065 病毒侵袭持续中 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. shell单引号中输出参数值

    因为在shell的单引号中,所有的特殊字符和变量都会变成文本,那么如果需要在字符串中输出变量值怎么办呢? 这里记录以下两种方法: 使用双引号 shell> X='parameter' shell ...

  4. python3中输出不换行

    python2中输出默认是换行的,为了抑制换行,是这么做的: print x, 到了python3中,print变成一个函数,这种语法便行不通了.用2to3工具转换了下,变成这样了: print(x, ...

  5. 在 ASP.NET MVC Web 应用程序中输出 RSS Feeds

    RSS全称Really Simple Syndication.一些更新频率较高的网站可以通过RSS让订阅者快速获取更新信息.RSS文档需遵守XML规范的,其中必需包含标题.链接.描述信息,还可以包含发 ...

  6. 在JSP页面中输出JSON格式数据

    JSON-taglib是一套使在JSP页面中输出JSON格式数据的标签库. JSON-taglib主页: http://json-taglib.sourceforge.net/index.html J ...

  7. MVC中如何在controller的action中输出JS到页面上

    MVC中如何在controller的action中输出JS到页面上 可以通过Http上下文对象(httpContext)就可以了,在Action中的HttpContext就是这个Action所指向的页 ...

  8. makefile中使用echo向文件中输出版本号和编译时间

    @echo "#define BUILD_TIME" `date +"%F_%H:%M:%S"` > buildTime_svnVer.h @echo & ...

  9. 在jsp中用一数组存储了数据库表中某一字段的值,然后在页面中输出其中的值。

    List<String> list = new ArrayList<String>();  String sql = "select userName from us ...

随机推荐

  1. 【Asp.net入门5-04】SportsStore之添加分页

  2. 网络优化之net.ipv4.tcp_tw_recycle参数

    不要在linux上启用net.ipv4.tcp_tw_recycle参数  2015/07/27  CFC4N 本文为翻译英文BLOG<Coping with the TCP TIME-WAIT ...

  3. 四大开源协议比较:BSD、Apache、GPL、LGPL

    sklearn实战-乳腺癌细胞数据挖掘(博客主亲自录制视频教程) https://study.163.com/course/introduction.htm?courseId=1005269003&a ...

  4. group by实现原理及其作用

    mysql中group by实现方式有三种,松散索引,紧凑索引,临时文件(文件排序). 在网上看了相关的介绍,大部分介绍都比较晦涩难懂,这里说下我的理解. 在学习SQL优化时,我们都知道可以对grou ...

  5. 《剑指offer》 面试题53 :正则表达式匹配 Java

    引言:这道题情况比较复杂,边界条件较多,为了便于以后复习,整理一下.另外,由于C语言和Java对于字符串的操作存在不一样的地方,代码也存在改动. 题目:请实现一个函数用来匹配包含'.'和'*'的正则表 ...

  6. Kafka 0.8 Consumer处理逻辑

    0.前言 客户端用法: kafka.javaapi.consumer.ConsumerConnector consumer = kafka.consumer.Consumer.createJavaCo ...

  7. 你知道吗?undefined 与 null 的区别

    大多数计算机语言,有且仅有一个表示"无"的值,比如,C语言的NULL,Java语言的null,Python语言的none,Ruby语言的nil. 有点奇怪的是,JavaScript ...

  8. Pycharm和IntelliJ IDEA激活 2017.3.x版本

    PyCharm 2017.3.3 (Professional Edition) 已经屏蔽了http://www.imsxm.com/   http-server激活方式,我根据参考教程搭建了一个,如有 ...

  9. ubuntu 14.04安装JDK

    As a workaround, you can install OpenJDK 8 from a PPA repository: 1. Open terminal from the Dash or ...

  10. 图片压缩之 PNG

    作者:程志达链接:https://zhuanlan.zhihu.com/p/19570424来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. PNG(Portable N ...