LOJ10065

版权声明:发现蒟蒻ff_666,但转载请注明 https://blog.csdn.net/qq_42403731/article/details/81982749

LOJ10065

先求一趟正常的PRIM
贪心想法,显然是将后大的几个给卫星,然后就OK了

#include<bits/stdc++.h>
#define gt() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++)
#define D(i,j) ((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y))
using namespace std;
static char buf[1000000],*p1=buf,*p2=buf;
const int maxn=505,INF=1e9;
int n,k,Ans,dst[maxn];bool vis[maxn];
struct ff{
    int x,y;
}a[maxn];
int read(){
    int ret=0;char ch=gt();
    while(ch<'0'||ch>'9') ch=gt();
    while(ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=gt();
    return ret;
}
int main(){
    n=read(),k=read();
    for(int i=1;i<=n;i++) a[i]=(ff){read(),read()};
    for(int i=2;i<=n;i++) dst[i]=D(1,i);
    for(int i=1;k<n&&i<n;i++){
        int min_x=INF,id;
        for(int j=2;j<=n;j++)if(!vis[j]&&dst[j]<min_x) min_x=dst[j],id=j;
        vis[id]=1;
        for(int j=2;j<=n;j++)if(!vis[j]&&D(id,j)<dst[j]) dst[j]=D(id,j);
    }
    nth_element(dst+1,dst+n-k+1,dst+1+n);
    printf("%.2lf",sqrt(1.0*dst[n-k+1]));
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42403731/article/details/81982749