本文主要是介绍swustoj最近对问题(0794),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
设p1=(x1, y1), p2=(x2, y2), …, pn=(xn, yn)是平面上n个点构成的集合S,设计算法找出集合S中距离最近的点对。
多组测试数据,第一行为测试数据组数n(0<n≤100),每组测试数据由两个部分构成,第一部分为一个点的个数m(0<m≤1000),紧接着是m行,每行为一个点的坐标x和y,用空格隔开,(0<x,y≤100000)
每组测试数据输出一行,为该组数据最近点的距离,保留4为小数。
1 2 3 4 5 6 7 8 | 2 2 0 0 0 1 3 0 0 1 1 1 0 |
1 2 | 1.0000 1.0000 |
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include<stack>
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
struct node
{double x, y;
};
node ss[1000000];
int main()
{int t;cin >> t;while (t--){int n;node s[1005];cin >> n;for (int i = 0; i < n; i++){cin >> s[i].x >> s[i].y;}int k = 0;double ans = 99999999.0;for (int i = 0; i < n; i++){for (int j = i + 1; j < n; j++){ans = min(ans, sqrt(pow(s[i].x - s[j].x, 2) + pow(s[i].y - s[j].y, 2)));}}printf("%.4lf\n", ans);}return 0;
}
这篇关于swustoj最近对问题(0794)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!