1007
2010-11-05 20:39
162 查看
二分思想:
#include <iostream> #include <cmath> #include <algorithm> using namespace std; struct point{ double x,y; bool operator <(point other)const{ return x<other.x||(x==other.x&&y<other.y); } } p[100000],tp[100000]; bool cmpy(point a, point b){ return a.y<b.y; } double Gao(int s,int e){ if(s==e) return 1e100; int m=(s+e)/2; double l=Gao(s,m); double r=Gao(m+1,e); double ans=min(l,r); int cnt=0; for(int i=s; i<=m; ++i){ if(p[m].x-p[i].x<ans){ tp[cnt++]=p[i]; } } for(int i=m+1; i<=e; ++i){ if(p[i].x-p[m+1].x<ans) tp[cnt++]=p[i]; } sort(tp,tp+cnt,cmpy); for(int i=0; i<cnt; ++i){ for(int j=i+1; j<cnt; ++j){ if(tp[j].y-tp[i].y>=ans) break; ans=min(sqrt((tp[i].x-tp[j].x)*(tp[i].x-tp[j].x)+(tp[i].y-tp[j].y)*(tp[i].y-tp[j].y)),ans); } } return ans; } int main(){ int n; while(scanf("%d",&n)){ if(n==0) break; for(int i=0; i<n; ++i) scanf("%lf%lf",&p[i].x,&p[i].y); sort(p,p+n); printf("%.2lf/n",Gao(0,n-1)/2); fflush(stdout); } }
相关文章推荐
- 1007. Maximum Subsequence Sum
- 1007. 素数对猜想 (20)
- HDU1007——Quoit Design
- CSUOJ 1007 矩形着色
- 1007 DNA Sorting
- POJ 1007解题报告
- POJ 1007
- 人民大学云计算编程的网上评估平台--解题报告 1004-1007
- hdu 1007 Quoit Design (最近点对、分治)
- XDOJ_1007解题报告
- PAT 1007
- POJ 1007 DNA Sorting
- PAT 1007 Maximum Subsequence Sum
- hdu4366-successor-2012 Multi-University Training Contest 7-1007
- http://ac.jobdu.com/problem.php?pid=1007
- 1007
- BIT寒假练习-2013__1007:Number Converter
- PKU_1007_DNA Sorting
- 分治算法五(最近点对---杭电OJ 1007 Quoit Design)
- 九度论坛-1007