HDU1007+最近点对
来源:互联网 发布:教父 知乎 编辑:程序博客网 时间:2024/04/30 12:46
模板题,不解释。
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>#include<math.h>using namespace std;const double eps = 1e-8;const int maxn = 100005;const double inf = 9999999999.0;struct Point {double x,y;};struct Line{Point a,b;};Point pnt[ maxn ],temp[ maxn ];double dis( Point a,Point b ){return sqrt( (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y) );}int cmpxy( Point a,Point b ){if( a.x!=b.x )return a.x<b.x;elsereturn a.y<b.y;}int cmpx( Point a,Point b ){return a.x<b.x;}int cmpy( Point a,Point b ){return a.y<b.y;}double solve( int L,int R ){if( L==R )return inf;if( L+1==R )return dis( pnt[L],pnt[R] );int mid = (L+R)/2;double Ldis,Rdis;Ldis=solve( L,mid );Rdis=solve( mid+1,R );double res = min( Ldis,Rdis );int cnt = 0;for( int i=L;i<=R;i++ ){if( fabs( pnt[i].x-pnt[mid].x )<=res ){temp[ cnt++ ] = pnt[i];}}//分离出宽度为RES的点sort( temp,temp+cnt,cmpy );for( int i=0;i<cnt;i++ ){for( int j=i+1;j<cnt;j++ ){if( fabs(temp[i].y-temp[j].y)>res ) break;res = min( res,dis(temp[i],temp[j]) );}}return res;}int main(){int n;while( scanf("%d",&n),n ){for( int i=0;i<n;i++ )scanf("%lf%lf",&pnt[i].x,&pnt[i].y);sort( pnt,pnt+n,cmpxy );double Ans = solve( 0,n-1 );printf("%.2lf\n",Ans/2.0);}return 0;}
- hdu1007最近点对
- HDU1007+最近点对
- hdu1007最近点对
- hdu1007 最近点对
- hdu1007 平面最近点对
- HDU1007(最近点对问题)
- HDU1007最近点对问题
- HDU1007 平面最近点对
- HDU1007经典最近点对
- HDU1007 查找平面最近点对
- hdu1007 Quoit Design(最近点对)
- hdu1007 Quoit Design (最近点对)
- 最近点对,zoj 2107,hdu1007
- hdu1007分治法求最近点对
- HDU1007 查找平面最近点对
- HDU1007 Quoit Design (平面最近点对)
- hdu1007最近点对(分治)
- hdu1007求最近点对(分治法)
- 小糖的糖果
- Lecture 3 (二)
- POJ3714+最近点对
- int Serializable导致的Provided id of the wrong type. Expected异常
- Linux下使用JNI的常见问题及解决方案
- HDU1007+最近点对
- UVA 550 Multiplying by Rotation 数论的规律
- Zend Framework2学习一:介绍
- 黑马程序员----【张孝祥7K面试题】一交通灯管理系统视频学习笔记
- hdu 1010 Tempter of the Bone(dfs+奇偶剪枝)
- 用Visual Studio2010 编译 C++文件"hello world”
- TCP/IP详解学习笔记(1)
- 怎样计算两个时间之间的间隔
- vc对Excel