结构体stu的大小啥的咋判断的阿?
查看原帖
结构体stu的大小啥的咋判断的阿?
1143869
1979281699lxy楼主2024/2/29 17:13
#include<stdio.h>
#include<math.h>
int s, p;
int a[100000], b[100000], fa[100000];
int n, sum;
double ans;
struct node {
	double x, y, z;
}stu[1000001];///666   为啥这里少个0就过//
//了??题目没这么大吧??

void swap(struct node* x, struct node* y)
{
	struct node temp = *x;
	*x = *y;
	*y = temp;
}

int find(int x)
{
	if (fa[x] == x)	return x;
	else
	{
		fa[x] = find(fa[x]);
		return	fa[x];
	}
}

void qsort(int start, int end)
{
	if (start >= end)	return;
	int left = start, right = end;
	int key = left;
	while (left < right)
	{
		while (stu[right].z >= stu[key].z && left < right) {
			right--;
		}
		while (stu[left].z <= stu[key].z && left < right) {
			left++;
		}
		swap(&stu[left], &stu[right]);
	}swap(&stu[key], &stu[right]);
	key = right;
	qsort(start, key - 1);
	qsort(key+1, end);
}

int main()
{
	scanf("%d %d", &s, &p);
	for (int i = 1; i <= p; i++)
	{
		scanf("%d %d", &a[i], &b[i]);
		for (int j = 1; j < i; j++)
		{
			n++;
			stu[n].z = sqrt((a[i] - a[j]) * (a[i] - a[j]) + (b[i] - b[j]) * (b[i] - b[j]));
			stu[n].x = i;
			stu[n].y = j;
		}
	}
	for (int i = 1; i <= p; i++) {//初始化
		fa[i] = i;
	}
	qsort(1,n);//快排边
	for (int i = 1; i <= n; i++)//不要混淆  n    p
	{
		if ((find(stu[i].x)) != (find(stu[i].y))) {
			fa[find(stu[i].x)] = find(stu[i].y);
			ans = stu[i].z;
			sum++;
			if (sum >= p - s) {
				printf("%.2lf", ans);
				return 0;
			}
		}
	}
	return 0;
}

2024/2/29 17:13
加载中...