求助dalao
查看原帖
求助dalao
691315
SNXL楼主2023/8/27 17:12
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <sstream>
#include <cstring>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <string>
#define int long long
using namespace std;
const int M = 500, N = M * M + 10;
const int INF = numeric_limits<int>::max() - 0x3f3f3f3f3f;
inline int read () {
    register int x = 0 , ch = getchar();
    while( !isdigit(ch)) ch = getchar();
    while( isdigit(ch) ) x = x * 10 + ch - '0' , ch = getchar();
    return x;
}
struct node {
	int u, v;
	double val;
	bool operator < (const node & o) const {
		return val < o.val;
	}
}a[N];
struct hhh {
	int x, y;
	void input() {
		cin >> x >> y;
	}
}p[M];
int n, m, fw, f[N], cnt;
int find(int x) {
	return f[x] == x ? x : f[x] = find(f[x]);
}
void U(int x, int y, int i) {
	int rx = find(x), ry = find(y);
	if (rx == ry) return;
	f[rx] = ry;
	cnt++;
	if (cnt == n - fw) {
		cout << fixed << setprecision(2) << a[i].val;
	}
}
signed main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin >> fw >> n;
	for (int i = 1; i <= n; i++) f[i] = i;
	for (int i = 1; i <= n; i++) {
		p[i].input();
	}
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			double sum = (1.0 * (p[i].x - p[j].x) * (p[i].x - p[j].x) + 
				(p[i].y - p[j].y) * (p[i].y - p[j].y));
			a[++m] = {i, j, (double)sqrt(sum)};
		}
	}
	sort (a + 1, a + m + 1);
	for (int i = 1; i <= m; i++) {
		U(a[i].u, a[i].v, i);
	}
	cout << '\n';
	return 0;
}

2023/8/27 17:12
加载中...