分治求解,二维空间最近点对。
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long LL;
const int maxn=100005;
struct Point
{
int x , y;
};
Point p[maxn];
inline LL Distance(Point a,Point b)
{
int dx = a.x - b.x , dy = a.y - b.y;
return (LL) dx * dx + (LL)dy * dy;
}
bool cmpx(Point a,Point b)
{
return a.x < b.x;
}
bool cmpy(int a,int b)
{
return p[a].y < p[b].y;
}
int ypos[maxn];
///Call closedis(p, 1, n);
LL closedis(Point *p, int l, int r)
{
if(l == r)return 1LL << 62;
if(l+1 == r) return Distance(p[l], p[r]);
int mid=(l+r)/2;
LL ans = min(closedis(p, l, mid), closedis(p, mid+1, r));
int num = 0;
for(int i = l; i <= r; i++)
{
if((LL)(p[i].x - p[mid].x) * (p[i].x - p[mid].x) <= ans)
ypos[num+&#