#include<iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef struct Point//定义点对
{
double x,y;
}Point;
void getPoint(Point *array,int length)//产生[-100,100]以内的随机点对
{
srand(unsigned(time(nullptr)));
for(int i=0;i<length;i++)
{
array[i].x=(rand()%20000)/100.0-100.0;
array[i].y=(rand()%20000)/100.0-100.0;
}
}
double Distance(Point a,Point b)//计算点对之间的距离
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool cmp(Point a,Point b)//定义sort函数排序规则,将点对按x轴大小排序
{
return a.x<b.x;
}
double findClose(Point array[],int length,Point &a,Point &b)//寻找最近点对
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余3页未读,立即下载