最近对问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sunone_/article/details/53133096

说明

使用蛮力法,把所有点遍历一遍,找到最小

#include<iostream>
#include<iomanip>
using namespace std;
struct Point
{
	double x, y;
}point[1000];

int main()
{
	double min = 99999999;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> point[i].x >> point[i].y;
	for (int i = 0; i < n-1; i++)
	{
		for (int j = i+1; j < n; j++)
		{
			double d = sqrt((point[j].x - point[i].x)*(point[j].x - point[i].x) +
				(point[j].y - point[i].y)*(point[j].y - point[i].y));
			if (d < min)
				min = d;
		}
	}
	cout <<min << endl;
    return 0;
}

在这里插入图片描述
欢迎关注本人微信公众号,更好技术和行业好文等您收看!

猜你喜欢

转载自blog.csdn.net/sunone_/article/details/53133096