POJ 2349 Arctic Network (the bottom spanning tree + beg K large side)

Source: Internet
Author: User

Title Link: http://poj.org/problem?id=2349

The main topic: There are n outposts, and S satellite communication devices, any two satellite communication devices can communicate through satellites, regardless of their location. Otherwise, only the distance between two outposts does not exceed D to communicate over the radio. Find the smallest d that enables all outposts to communicate directly or indirectly.

Problem-Solving ideas: The topic requires that all outposts can communicate directly or indirectly, then the equivalent of n points connected, at least the need to n-1 edge. N points can be divided into S groups, each intra-group unlimited communication, between the regiment and the group through satellite communications. Then it is equivalent to use the S satellite device to establish S-1 edge, with radio communication to establish n-1-(s-1) ==n-s edge, because the satellite communication is no distance limit that can choose the largest s-1 edge, that D is the left-n-S bar edge of the longest side distance.

Code:

1#include <iostream>2#include <cstdio>3#include <math.h>4#include <cstring>5#include <algorithm>6 using namespacestd;7 Const intn=1e3+5;8 9 structnode2{Ten     intx, y; One }a[n]; A  - structnode{ -     intx, y; the     Doubledis; - node () {} -NodeintXintYDoubledis) { -          This->x=x; +          This->y=y; -          This->dis=dis; +     } A     BOOL operator< (ConstNode &b)Const{ at         returndis<B.dis; -     } -}edge[n*N]; - intRoot[n]; -  - intFindintx) { in     returnroot[x]==x?x:root[x]=find (Root[x]); - } to  + intMain () { -     intT; thescanf"%d",&t); *      while(t--){ $         intS,n;Panax Notoginsengscanf"%d%d",&s,&n); -          for(intI=1; i<=n;i++){ thescanf"%d%d",&a[i].x,&a[i].y); +root[i]=i; A         } the         intCnt=0; +          for(intI=1; i<=n;i++){ -              for(intj=i+1; j<=n;j++){ $                 DoubleDIS=SQRT (1.0* (a[i].x-a[j].x) * (a[i].x-a[j].x) + (A[I].Y-A[J].Y) * (a[i].y-a[j].y)); $edge[++cnt]=node (i,j,dis); -             } -         } theSort (edge+1, edge+1+CNT); -         Wuyi         intedge_num=0; the         Doubleans; -          for(intI=1; i<=cnt;i++){ Wu             intx=find (edge[i].x); -             inty=find (EDGE[I].Y); About             if(x!=y) { $edge_num++; -root[x]=y; -                 //Remove the maximum s-1 edge from the N-1 bar in the smallest spanning tree (because there is a S satellite station, which is equivalent to the S-point, then the s-1 edge) -                 //in the remaining n-s bars, the largest side length is the one that is asked A                 if(edge_num==n-s) { +ans=Edge[i].dis; the                      Break; -                 } $             } the         } theprintf"%.2f\n", ans); the     } the     return 0; -}

POJ 2349 Arctic Network (the bottom spanning tree + beg K large side)

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.