POJ 3714 最近点对
来源:互联网 发布:知乎专栏有稿费吗 编辑:程序博客网 时间:2024/05/15 13:39
题意:给出两个点的集合,求属于不同集合的最近点对。
这题是最近点对的变形,在求两点距离的时候加以判断是否来自不同集合就行。
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;#define maxn 200005struct point{ double x,y; int f;} p[maxn],p1[maxn];int cmpx(point a,point b){ return a.x<b.x;}int cmpy(point a,point b){ return a.y<b.y;}double dis(point a,point b){ if(a.f!=b.f) return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); return 1e30;}double getmin(int l,int r){ double ans; if(l>=r) return 1e30; if(l+1==r) return dis(p[l],p[r]); int m=(l+r)>>1; ans=min(getmin(l,m),getmin(m+1,r)); int cn=0; for(int i=l; i<=r; i++) if(fabs(p[i].x-p[m].x)<ans) p1[cn++]=p[i]; sort(p1,p1+cn,cmpy); for(int i=0; i<cn; i++) for(int j=i+1; j<cn&&p1[j].y-p1[i].y<ans; j++) ans=min(ans,dis(p1[i],p1[j])); return ans;}int main(){ int t,n; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=0; i<n; i++) scanf("%lf%lf",&p[i].x,&p[i].y),p[i].f=0; for(int i=n; i<n+n; i++) scanf("%lf%lf",&p[i].x,&p[i].y),p[i].f=1; sort(p,p+n+n,cmpx); printf("%.3f\n",getmin(0,n+n-1)); } return 0;}
- POJ 3714 最近点对
- poj 3714 最近点对
- POJ 3714 最近点对
- POJ 3714 变种最近点对
- POJ 3714 Raid 最近点对
- poj 3714 变形的最近点对
- poj 3714 Raid(最近点对)
- 寻找最近点对(POJ 3714)
- POJ 3714 Raid 最近对点题解
- POJ 3714 Raid 平面最近点对
- POJ 3714 Raid 最近点对
- POJ 3714 Raid(最近点对)
- poj 3714Raid(最近点对)
- POJ 3714(Raid-平面最近点对)
- POJ 3714 Raid(最近点对)
- 平面上最近点对的距离 POJ 3714
- poj 3714 Raid (类型不同点间的最近点对)
- poj 3714 杭电 1007(最近点对)
- __attribute__
- Android中Bitmap和Drawable
- 面试题30:两个链表的第一个公共结点
- JQuery操作checkbox
- hdu1054(二分图+最小点覆盖数+匈牙利算法)
- POJ 3714 最近点对
- 如何下载资源
- hdu 2050 折线分割平面
- 数据中心overlay
- java的double的精度问题
- 预编译头的使用
- 黄淮学院CSDN高校俱乐部项目开发之湖北省人力资源一点通
- Virtual Box和VMware Workstation
- 黑马程序员-反射