60pts求助
查看原帖
60pts求助
1007041
zhaozichu楼主2025/1/20 21:47
#include<bits/stdc++.h>
using namespace std;
int s,n,c[505],l[505],r[505],n2,n3,o;
struct node {
	int x,y;
	double s;
} a[1000000];
struct node2 {
	int q,p;
	double s2;
} b[1000000];
int find(int x){
	if(c[x]==x)return x;
	return find(c[x]);
}
bool cmp(node a,node b) {
	return a.s<b.s;
}
bool cmp2(node2 a,node2 b) {
	return a.s2>b.s2;
}
int main() {
	cin>>s>>n;
	for(int i=1; i<=n; i++)cin>>l[i]>>r[i],c[i]=i;
	for(int i=1; i<=n; i++) {
		for(int j=i+1; j<=n; j++) {
			int l1=abs(l[i]-l[j]),l2=abs(r[i]-r[j]);
			a[n2].x=i;
			a[n2].y=j;
			a[n2++].s=sqrt(l1*l1+l2*l2);
		}
	}
	sort(a,a+n2,cmp);
//	for(int i=0;i<n2;i++)cout<<a[i].x<<" "<<a[i].y<<" "<<a[i].s<<endl;
//	cout<<endl;
	for(int i=0; i<n2; i++) {
		if(find(a[i].x)!=find(a[i].y)) {
//			for(int i=1; i<=n; i++)cout<<c[i]<<" ";
//			cout<<endl;
//			cout<<a[i].x<<" "<<a[i].y<<" "<<find(a[i].x)<<" "<<find(a[i].y)<<endl<<endl;
			c[find(a[i].y)]=find(a[i].x);
			b[n3].p=a[i].x;
			b[n3].q=a[i].y;
			b[n3++].s2=a[i].s;
		}
	}
	sort(b,b+n3,cmp2);
//	for(int i=0;i<n3;i++)cout<<b[i].p<<" "<<b[i].q<<" "<<b[i].s2<<endl;
	for(int i=0; i<n2; i++) {
		if(s<=1)break;
		s-=2;
		o++;
	}
	printf("%.2lf",b[o].s2);
	return 0;
}
2025/1/20 21:47
加载中...