分治法

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

  1. # include <iostream>
  2. # include <cstdio>
  3. # include <cstring>
  4. # include <algorithm>
  5. # include <string>
  6. # include <cmath>
  7. # include <queue>
  8. # include <list>
  9. # define LL long long
  10. using namespace std ;
  11.  
  12. const double eps = 1e-;
  13. const int MAXN = ;
  14. const double INF = 1e20;
  15. struct Point
  16. {
  17. double x,y;
  18. };
  19.  
  20. double dist(Point a,Point b)
  21. {
  22. return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
  23. }
  24.  
  25. Point p[MAXN];
  26. Point tmpt[MAXN];
  27. bool cmpxy(Point a,Point b)
  28. {
  29. if(a.x != b.x)return a.x < b.x;
  30. else return a.y < b.y;
  31. }
  32. bool cmpy(Point a,Point b)
  33. {
  34. return a.y < b.y;
  35. }
  36. double Closest_Pair(int left,int right)
  37. {
  38. double d = INF;
  39. if(left == right)return d;
  40. if(left + == right)
  41. return dist(p[left],p[right]);
  42. int mid = (left+right)/;
  43. double d1 = Closest_Pair(left,mid);
  44. double d2 = Closest_Pair(mid+,right);
  45. d = min(d1,d2);
  46. int k = ;
  47. for(int i = left;i <= right;i++)
  48. {
  49. if(fabs(p[mid].x - p[i].x) <= d)
  50. tmpt[k++] = p[i];
  51. }
  52. sort(tmpt,tmpt+k,cmpy);
  53. for(int i = ;i <k;i++)
  54. {
  55. for(int j = i+;j < k && tmpt[j].y - tmpt[i].y < d;j++)
  56. {
  57. d = min(d,dist(tmpt[i],tmpt[j]));
  58. }
  59. }
  60. return d;
  61. }
  62.  
  63. int main()
  64. {
  65. //freopen("in.txt","r",stdin) ;
  66. int n;
  67. while(scanf("%d",&n)== && n)
  68. {
  69. for(int i = ;i < n;i++)
  70. scanf("%lf%lf",&p[i].x,&p[i].y);
  71. sort(p,p+n,cmpxy);
  72. printf("%.2lf\n",Closest_Pair(,n-)/);
  73. }
  74. return ;
  75. }

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. Python【requests】第三方模块

    import requests print("===============get请求================")url = 'http://api.nnzhp.cn/ap ...

  2. nginx反向代理下载文件失败处理

    最近遇到了客户在从我们的服务器下载文件失败时的情况.然后把解决方案一并整理一下以备后续.需要说明的是,我们前端都是使用nginx来做反向代理,后面的逻辑处理采用php的方式. 1.缓存目录不可写 ng ...

  3. Shell记录-Shell命令(文件查找)

    常见解压/压缩命令 tar文件格式解包:tar xvf FileName.tar打包:tar cvf FileName.tar DirName(注:tar是打包,不是压缩!) .gz文件格式解压1:g ...

  4. Git记录-Git版本控制介绍

    git config命令用于获取并设置存储库或全局选项.这些变量可以控制Git的外观和操作的各个方面. 如果在使用Git时需要帮助,有三种方法可以获得任何git命令的手册页(manpage)帮助信息: ...

  5. 第二回 C#和JAVA 语法差异性对比

    1.继承  C#用 :  java用 extends 继承父类   implements 2.Java : 一个源文件中只能有一个public类  可以有多个非public类  源文件的名称应该和pu ...

  6. C语言的内存对齐

    从一个例子开始 象下面这样定义的结构体占几个字节? typedef struct{ char a; int i; } Sample; char占1个字节,int占4个字节,答案是5个字节? 错了.如果 ...

  7. 2016-2017-20155329 《Java程序设计》第7周学习总结

    学号 2016-2017-20155329 <Java程序设计>第7周学习总结 教材学习内容总结 时间的度量 格林威治标准时间(GMT时间) 世界时(UT) 国际原子时(TAI) 世界协调 ...

  8. windows 下 react-native(v0.56) Android 环境搭建踩坑记录

    debugservicereact-native 安装官网 https://reactnative.cn/docs/getting-started.html 根据官网步骤一步步执行下去.还能碰到一些问 ...

  9. Postman和Selenium IDE开局自带红蓝BUFF属性,就问你要还是不要

    话不多说,下面给大家介绍两款工具,selenium IDE和Postman. 为什么说是自带红蓝Buff,因为想做UI自动化和接口自动化的同学,很多时候,都难在了开头. 比如你要学习语言,你要学习框架 ...

  10. 2016.07.15——istringstream测试

    istringstream测试 1.istringstream strcin(str),字符串(str)可以包括多个单词,单词之间使用空格分开 #include "stdafx.h" ...