算法设计与分析中几何问题中的蛮力法——最近对问题

求完整代码,下面是部分算法

int ClosePoints(int x[], int y[], int n)

{

int index1, index2;

int  d, minDist = 10000;

for (int i = 0; i<n - 1; i++)

for (int j = i + 1; j <= n - 1; j++)

{

d = (x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j]);

if (d <= minDist)

{

minDist = d;

index1 = i;

index2 = j;

}

cout << "最近的点对是:" << index1 << "和" << index2<< endl;

        return minDist;

}


时代灬Y
浏览 1642回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP