最近点对
来源:互联网 发布:关闭windows数字签名 编辑:程序博客网 时间:2024/05/14 21:38
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<vector> #include<cmath> #include<queue> #include<stack> #include<map> #include<set> #include<algorithm> using namespace std; const int maxn=100010; const double INF=10000000000000.0; const int eps=1e-6; int N; double mind; struct node { double x,y; bool operator<(const node &a)const { if(fabs(x-a.x)<eps)return y<a.y; return x<a.x; } }p[maxn],tmp[maxn]; bool cmp(node a,node b) { return a.y<b.y; } double cal(node a,node b) { double x=a.x-b.x; double y=a.y-b.y; return sqrt(x*x+y*y); } double solve(int l,int r) { if(l==r)return INF; if(l+1==r)return cal(p[l],p[r]); int mid=(l+r)>>1; double d=INF; d=min(d,solve(l,mid-1)); d=min(d,solve(mid+1,r)); int k=0; for(int i=l;i<=r;i++) if(fabs(p[mid].x-p[i].x)<=d)tmp[k++]=p[i]; sort(tmp,tmp+k,cmp); for(int i=0;i<k;i++) { for(int j=i+1;j<k&&fabs(tmp[j].y-tmp[i].y)<=d;j++) { double dis=cal(tmp[i],tmp[j]); if(dis<d) d=dis; } } return d; } int main() {//freopen("in.txt","r",stdin); while(scanf("%d",&N)!=EOF) { for(int i=1;i<=N;i++)scanf("%lf%lf",&p[i].x,&p[i].y); sort(p+1,p+1+N); double ans=solve(1,N); printf("%.2lf\n",ans/2); } return 0; }
0 0
- 最近点对算法
- 最近点对
- 最近点对问题
- 求最近点对
- 最近点对
- 最近点对问题
- 平面最近点对
- 最近点对
- 求最近点对
- 平面最近点对
- 寻找最近点对
- 最近点对问题
- 2.11 最近点对
- 最近点对
- 求最近点对
- 最近点对问题
- 寻找最近点对
- 最近点对
- HDU3090 Go Home
- Zend Studio 安装+破解
- 字符和字符串
- poj 3628 Silver Cow Party (spfa)
- 插入排序(InsertSort)
- 最近点对
- 3D游戏《龙心传奇Dragona》全套完整源代码
- Scala隐式转换
- access提示"以独占方式打开或没有权限"的解决方法
- ceph存储 Linux远程操作(rcp/rsh)命令实战
- [Win32] UAC用户账户控制(提权+降权)
- 开始刷leetcode day72: Binary Tree Preorder Traversal
- 根据滑动距离图片做缩放
- Qt浅谈之三十系统托盘(QSystemTrayIcon)