hdu 1007 N个点中输出2点的最小距离的一半
分治法
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点的最小距离的一半的更多相关文章
- HDU 1007 Quoit Design(二分+浮点数精度控制)
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU 3065 病毒侵袭持续中
HDU 3065 病毒侵袭持续中 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- shell单引号中输出参数值
因为在shell的单引号中,所有的特殊字符和变量都会变成文本,那么如果需要在字符串中输出变量值怎么办呢? 这里记录以下两种方法: 使用双引号 shell> X='parameter' shell ...
- python3中输出不换行
python2中输出默认是换行的,为了抑制换行,是这么做的: print x, 到了python3中,print变成一个函数,这种语法便行不通了.用2to3工具转换了下,变成这样了: print(x, ...
- 在 ASP.NET MVC Web 应用程序中输出 RSS Feeds
RSS全称Really Simple Syndication.一些更新频率较高的网站可以通过RSS让订阅者快速获取更新信息.RSS文档需遵守XML规范的,其中必需包含标题.链接.描述信息,还可以包含发 ...
- 在JSP页面中输出JSON格式数据
JSON-taglib是一套使在JSP页面中输出JSON格式数据的标签库. JSON-taglib主页: http://json-taglib.sourceforge.net/index.html J ...
- MVC中如何在controller的action中输出JS到页面上
MVC中如何在controller的action中输出JS到页面上 可以通过Http上下文对象(httpContext)就可以了,在Action中的HttpContext就是这个Action所指向的页 ...
- makefile中使用echo向文件中输出版本号和编译时间
@echo "#define BUILD_TIME" `date +"%F_%H:%M:%S"` > buildTime_svnVer.h @echo & ...
- 在jsp中用一数组存储了数据库表中某一字段的值,然后在页面中输出其中的值。
List<String> list = new ArrayList<String>(); String sql = "select userName from us ...
随机推荐
- Python【requests】第三方模块
import requests print("===============get请求================")url = 'http://api.nnzhp.cn/ap ...
- nginx反向代理下载文件失败处理
最近遇到了客户在从我们的服务器下载文件失败时的情况.然后把解决方案一并整理一下以备后续.需要说明的是,我们前端都是使用nginx来做反向代理,后面的逻辑处理采用php的方式. 1.缓存目录不可写 ng ...
- Shell记录-Shell命令(文件查找)
常见解压/压缩命令 tar文件格式解包:tar xvf FileName.tar打包:tar cvf FileName.tar DirName(注:tar是打包,不是压缩!) .gz文件格式解压1:g ...
- Git记录-Git版本控制介绍
git config命令用于获取并设置存储库或全局选项.这些变量可以控制Git的外观和操作的各个方面. 如果在使用Git时需要帮助,有三种方法可以获得任何git命令的手册页(manpage)帮助信息: ...
- 第二回 C#和JAVA 语法差异性对比
1.继承 C#用 : java用 extends 继承父类 implements 2.Java : 一个源文件中只能有一个public类 可以有多个非public类 源文件的名称应该和pu ...
- C语言的内存对齐
从一个例子开始 象下面这样定义的结构体占几个字节? typedef struct{ char a; int i; } Sample; char占1个字节,int占4个字节,答案是5个字节? 错了.如果 ...
- 2016-2017-20155329 《Java程序设计》第7周学习总结
学号 2016-2017-20155329 <Java程序设计>第7周学习总结 教材学习内容总结 时间的度量 格林威治标准时间(GMT时间) 世界时(UT) 国际原子时(TAI) 世界协调 ...
- windows 下 react-native(v0.56) Android 环境搭建踩坑记录
debugservicereact-native 安装官网 https://reactnative.cn/docs/getting-started.html 根据官网步骤一步步执行下去.还能碰到一些问 ...
- Postman和Selenium IDE开局自带红蓝BUFF属性,就问你要还是不要
话不多说,下面给大家介绍两款工具,selenium IDE和Postman. 为什么说是自带红蓝Buff,因为想做UI自动化和接口自动化的同学,很多时候,都难在了开头. 比如你要学习语言,你要学习框架 ...
- 2016.07.15——istringstream测试
istringstream测试 1.istringstream strcin(str),字符串(str)可以包括多个单词,单词之间使用空格分开 #include "stdafx.h" ...