Uvaoj10369-arctic Network

Source: Internet
Author: User

1 /*2 the first line of all test case contains 1 <= S <=, the number of satellite channels!3 Note: s indicates how many satellites there are, so there is a maximum of S-1 channels! Then remove the S-1 channel behind the smallest spanning tree. 4 idea: The smallest minimum edge in the minimum spanning tree! 5 */6 //Kruskal algorithm .....7#include <iostream>8#include <cstdio>9#include <cstring>Ten#include <algorithm> One#include <cmath> A using namespacestd; -  - Doublex[ -], y[ -]; the  - structnode{ -    intu, v; -    DoubleD; + }; -  + BOOLCMP (Node A, Node B) { A     returnA.D <B.D; at } -  - intf[505]; -  -Node nd[150000]; - Doubleret[505]; in  - intGetfather (intx) { to    returnX==F[X]? x:f[x]=Getfather (f[x]); + } -  the BOOLUnion (intAintb) { *    intFa=getfather (a), fb=Getfather (b); $    if(fa!=FB) {Panax Notoginsengf[fa]=FB; -        return true; the    } +    return false; A } the  + intMain () { -    intN, M; $    intT; $scanf"%d", &t); -     while(t--){ -scanf"%d%d", &m, &n); the         for(intI=1; i<=n; ++i) { -scanf"%LF%LF", &x[i], &y[i]);Wuyif[i]=i; the        } -        intCnt=0; Wu         for(intI=1; i<n; ++i) -            for(intj=i+1; j<=n; ++j) { Aboutnd[cnt].u=i; $nd[cnt].v=J; -Nd[cnt++].d=sqrt ((X[i]-x[j]) * (X[i]-x[j]) + (Y[i]-y[j]) * (y[i]-y[j])); -           } -Sort (ND, nd+CNT, CMP); A        intCc=0; +         for(intI=0; i<cnt; ++i) the           if(Union (nd[i].u, ND[I].V)) -ret[cc++]=nd[i].d; $          for(intI=0; i<cc; ++i) thecout<<ret[i]<<"FDSF"<<Endl; theprintf"%.2lf\n", ret[n-m-1]); the    } the    return 0; -}

1 //Prim algorithm ....2#include <iostream>3#include <cstdio>4#include <cstring>5#include <algorithm>6#include <cmath>7 using namespacestd;8 Const DoubleINF =0x3f3f3f3f*1.0;9 Doublex[ -], y[ -];Ten  One intN, M; A Doublemap[505][505]; - intvis[505]; -  the Doubleret[505]; -  - voidPrim () { -memset (Vis,0,sizeof(Vis)); +vis[1]=1; -      for(intI=2; i<=n; ++i) +ret[i]=INF; A     introot=1, p; at      for(intI=1; i<n; ++i) { -         Doubleminlen=INF; -          for(intj=2; j<=n; ++j) { -            if(!vis[j] && ret[j]>Map[root][j]) -ret[j]=Map[root][j]; -            if(!vis[j] && minlen>Ret[j]) { inminlen=Ret[j]; -p=J; to            } +         } -root=p; thevis[root]=1; *     } $ }Panax Notoginseng  - intMain () { the     +    intT; Ascanf"%d", &t); the     while(t--){ +scanf"%d%d", &m, &n); -         for(intI=1; i<=n; ++i) $scanf"%LF%LF", &x[i], &y[i]); $         for(intI=1; i<n; ++i) -            for(intj=i+1; j<=n; ++j) -Map[i][j]=map[j][i]=sqrt ((X[i]-x[j]) * (X[i]-x[j]) + (Y[i]-y[j]) * (y[i]-y[j])); the  - Prim ();WuyiSort (ret, ret+n+1); the         -printf"%.2lf\n", ret[n-m+1]); Wu    } -    return 0; About}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.