平面最小点对 模板(hdu1007 uva10245)
来源:互联网 发布:修改linux 7主机名 编辑:程序博客网 时间:2024/05/21 01:57
#include<bits/stdc++.h>using namespace std;typedef long long ll;const int INF=0x3f3f3f3f;struct node1{ double x,y;}node[100010];int cmpx(node1 p1,node1 p2){ return p1.x<p2.x;}int cmpy(node1 p1,node1 p2){ return p1.y<p2.y;}double dis(int x,int y){ return sqrt((node[x].x-node[y].x)*(node[x].x-node[y].x)+(node[x].y-node[y].y)*(node[x].y-node[y].y));}double solve(int a,int b){ if(a+1==b) return dis(a,b); if(a==b) return INF*1.0; int mid=(a+b)/2; double d=min(solve(a,mid),solve(mid+1,b)); int l=mid,r=mid; int flag1=0; int flag2=0; while(l>=a&&d>node[mid].x-node[l].x) { flag1=1; l--; } while(r<=b&&d>node[r].x-node[mid].x) { flag2=1; r++; } if(flag1) l=l+1; if(!flag2) r=r+1; sort(node+l+1,node+r,cmpy); for(int i=l+1;i<r-1;i++) for(int j=i+1;j<r&&node[j].y-node[i].y<d;j++) { d=min(dis(i,j),d); } return d;}int main(){ int n; while(scanf("%d",&n)!=EOF&&n) { for(int i=0;i<n;i++) scanf("%lf%lf",&node[i].x,&node[i].y); sort(node,node+n,cmpx); printf("%.2f\n",solve(0,n-1)/2); } return 0;}
0 0
- 平面最小点对 模板(hdu1007 uva10245)
- hdu1007最小点对
- HDU1007--最小点对
- hdu1007 平面最近点对
- HDU1007 平面最近点对
- hdu1007 Quoit Design 平面最近点对(分治)
- HDU1007 查找平面最近点对
- HDU1007 查找平面最近点对
- HDU1007 Quoit Design (平面最近点对)
- 分治法求最小点对(hdu1007)
- hdu1007 Quoit Design(最近点对模板题)
- hdu1007 Quoit Design【平面最近点对+分治】
- hdu1007 Quoit Design(最近点对)
- hdu1007最近点对(分治)
- hdu1007.最近点对(分治法)
- 最近点对问题(hdu1007)
- hdu1007最近点对
- HDU1007+最近点对
- Hash
- 温习设计模式单列
- ORA-00911: 无效字符 问题和解决
- Effects特效包之“上帝之光”Sun Shafts 光线特效
- Maven引用本地jar到pom.xml
- 平面最小点对 模板(hdu1007 uva10245)
- 我们是如何构建 Twitter Lite 的
- patterns
- 20170420
- 题目1176:树查找
- span标签居中显示的正确方法
- Ubuntu16.04 安裝後無法打開wifi問題
- mysql删除重复数据只保留id最大一条记录
- Eclipse 打jar三种不同方式的区别