ZOJ 2107
来源:互联网 发布:汉字笔顺演示软件 编辑:程序博客网 时间:2024/06/16 00:01
平面最近点对问题。。
这题以前看过一篇文章。貌似只用比较最近的6个点左右(X轴排序过的)就可以了。。
A B C G
D E F H
假设这8个点在一个矩形上。。可以知道平面最近点对。。就是X轴周围的12个点中。。 O(n)算法就能过掉了。。
#include <queue> #include <stack> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <iostream> #include <limits.h> #include <string.h> #include <algorithm> using namespace std; const int MAX = 100010; const double D_MAX = 1e50; const double eps = 1e-15; struct point{ double x,y; }; point p[MAX];bool xy(double x,double y) // x < y { return x < y - eps; } bool dd(double x,double y) // x == y { return fabs( x - y ) < eps; } bool cmp(point a,point b) { if( dd(a.x,b.x) ) return xy(a.y,b.y); return xy(a.x,b.x); } double disp(point a,point b) { return sqrt( (a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y) ); } double nearpot(int l,int r) { double ans = D_MAX;for(int i = l;i <= r;i++){for(int j = 1; i+j <= r && j <= 6;j++){ans = min(ans,disp(p[i],p[j+i]));}}return ans;}int main(){int n; while( ~scanf("%d",&n) && n ) { for(int i=0; i<n; i++) scanf("%lf %lf",&p[i].x,&p[i].y); sort(p,p+n,cmp); double ans = nearpot(0,n-1); printf("%.2lf\n",ans/2.0); } return 0; }
0 0
- zoj 2107
- ZOJ 2107
- zoj 2107 Quoit Design
- zoj 2107最短点对
- zoj 2107 : Quoit Design
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- JAVA正则表达式
- 寻找矩阵中的鞍点
- 一些常用的样式
- 程序员:伤不起的三十岁
- 【大话QT之四】ctkPlugin插件系统实现项目插件式开发
- ZOJ 2107
- 4-oracle-启动流程分析
- 查看数据库名 查看实例名 服务名
- ios安全攻防(五)使用Cycript修改支付宝app运行时
- 深入浅出Android makefile
- shell分割字符串
- ros opencv camera_driver
- hadoop 安装出现的几种异常的处理方法,hadoop无法启动,no namenode to stop问题的解决方法,no datanode
- 不懂的题目