跑个O(n^2),没啥可说的,直接上代码和数据。
C++代码
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 10005;
typedef struct Point
{
double x;
double y;
} point;
point p[maxn];
double getlen(point p1, point p2)
{
return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}
int main()
{
int n;
while (cin >> n && n)
{
for (int i = 0; i < n; i++) cin >> p[i].x >> p[i].y;
double min_len = INF;
double x1, y1, x2, y2;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (i == j) continue;
double len = getlen(p[i], p[j]);
if (len < min_len)
{
min_len = len;
x