文档介绍:用分治法求解平面点集最接近点对问题
#include ""
#include <iostream>
#include <>
using namespace std;
void merge_sort1(POINT X[],int n)
{
int Min;
float temp;
for (int i=0;i<n;i++)
{
Min=i;
for (int j=i+1;j<n;j++)
if (X[j].x<X[Min].x)
Min=j;
if (Min!=i)
{
temp=X[i].x;
X[i].x=X[Min].x;
X[Min].x=temp;
temp=X[i].y;
X[i].y=X[Min].y;
X[Min].y=temp;
}
}
}
void merge_sort2(A_POINT X[],int n)
{
int Min,index;
float temp;
for (int i=0;i<n;i++)
{
Min=i;
for (int j=i+1;j<n;j++)
{
if (X[j].y<X[Min].y)
Min=j;
}
temp=X[i].x;
X[i].x=X[Min].x;
X[Min].x=temp;
temp=X[i].y;
X[i].y=X[Min].y;
X[Min].y=temp;
index=X[i].index;
X[i].index=X[Min].index;
X[Min].index=index;
}
}
float dist(POINT a,POINT b)
{
float dx,dy;
dx=-; dy=-;
return (dx*dx+dy*dy);
}
void closest(POINT X[],A_POINT Y[],int low,int high,POINT &a,POINT &b,float &d)
{
int i,j,k,m;
POINT al,bl,ar,br;
float dl,dr;
if((high-low)==1)
{a=X[low];b=X[high];d=dist(X[low],X[high]);}
else if((high-low)==2)
{
dl=dist(X[low],X[low+1]);
dr=dist(X[low],X[low+2]);
d=dist(X[low+1],X[low+2]);
if((dl<=dr)&&(dl<=d))
{a=X[low];b=X[low+1];d=dl;}
else if(dr<=d)
{a=X[low];b=X[low+2];d=dr;}
else
{a=X[low+1];b=X[low+2];}
}
else
{
A_POINT *SL=new A_POINT[(high-low)/2+1];
A_POINT *SR=new A_POINT[(high-low)/2+1];
m=(high-l