Hangzhou Electric 1162Eddy ' s picture (minimum spanning tree)

Source: Internet
Author: User

Eddy ' s pictureTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 8107 Accepted Submission (s): 4106


Problem Descriptioneddy begins to like painting pictures recently, he's sure of himself to become a painter. Every day Eddy draws pictures in his small, and he usually puts off his newest pictures to let his friends appreciate . But the result of it can be imagined, the friends is not a interested in its picture. Eddy feels very puzzled,in order to change all friends's view to he technical of painting pictures, so Eddy creates a PR Oblem for the He Friends of you.
Problem descriptions as Follows:given some coordinates pionts on a drawing paper, every point links with the ink with The straight line, causes all points finally to link in the same place. How many distants does your duty discover the shortest length which the ink draws?

Inputthe First line contains 0 < n <=, the number of a point. For each point, a line follows; Each following line contains and real numbers indicating the (x, y) coordinates of the point.

Input contains multiple test cases. Process to the end of file.

Outputyour program prints a single real number to both decimal places:the minimum total length of ink lines that can Conne CT all the points.

Sample Input
31.0 1.02.0 2.02.0 4.0

Sample Output
3.41
Another template problem, the minimum spanning tree Kruskal algorithm, but the premium Manaus algorithm is not very useful, has been used Kruskal, but the premium Manaus algorithm can handle big data, which is presumably excellent: with AC code:
#include <stdio.h> #include <string.h> #include <math.h> #include <algorithm>using namespace std;struct Node {int start;int end;double dis;} T[10010];int CMP (node A,node b) {return A.dis <b.dis;} int per[110];int Find (int x) {int r=x;while (R!=per[r]) R=per[r];return R; int join (int x,int y) {int fx=find (x), int fy=find (y), if (fx!=fy) {Per[fx]=fy;return 1;} return 0;} int main () {int m,n,i,j,p;double x[110],y[110];while (scanf ("%d", &n)!=eof) {for (i=0;i<110;i++) per[i]=i;for (i= 0;i<n;i++) scanf ("%lf%lf", &x[i],&y[i]); int k=0;for (i=0;i<n;i++) for (j=i+1;j<n;j++) {t[k].start=i; T[k].end =j;t[k].dis =sqrt ((X[i]-x[j]) * (X[i]-x[j]) + (Y[i]-y[j]) * (Y[i]-y[j]); k++;} Sort (t,t+k,cmp);d ouble sum=0.00;for (i=0;i<k;i++) if (Join (t[i].start,t[i].end)) sum=sum+t[i].dis;printf ("%.2lf\ n ", sum);} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hangzhou Electric 1162Eddy ' s picture (minimum spanning tree)

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.