Original title address: http://poj.org/problem?id=2560
Freckles
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 7863 |
|
Accepted: 3776 |
Description
In an episode of the Dick Van Dyke Show, Little Richie connects the freckles on his Dad's back to form a picture of the Li Berty Bell. Alas, one of the freckles turns out to is a scar, so his Ripley ' s engagement falls through.
Consider Dick's back is a plane with freckles at various (x, y) locations. Your job is-to-tell Richie-to-connect the dots so as to minimize the amountof ink used. Richie connects the dots by drawing straight lines between pairs,possibly lifting the pen between lines. When Richie was done there must was asequence of connected lines from any freckle to any other freckle.
Input
The first line contains 0 < n <= and the number offreckles on Dick's back. For each freckle, a line follows; Each following linecontains-numbers indicating the (x, y) coordinates of the freckle.
Output
Your program prints a single real number to the Decimalplaces:the minimum total length of ink lines the can connect all Thefreckles.
Sample Input
3
1.0 1.0
2.0 2.0
2.0 4.0
Sample Output
3.41
Test instructions: Give you the point of N-Cartesian coordinate system, and calculate the weight of the minimum spanning tree.
1#include <stdio.h>2#include <math.h>3#include <string.h>4 Const intN = the, Infinity =0x3f3f3f3f;5 struct Point6 {7 Doublex;8 Doubley;9 }vertex[n];Ten DoubleDistance[n][n], d[n]; One BOOLCnt[n] = {0}; A intMainvoid) - { - intN, start, Mintag; the Doublesum, x, y; - while(~SCANF ("%d", &N)) - { - for(intI=0; i<n; ++i) +scanf"%LF%LF", &vertex[i].x, &vertex[i].y); - for(intI=0; i<n; ++i) + { ADistance[i][i] =Infinity; at for(intj=i+1; j<n; ++j) - { -x = vertex[i].x-vertex[j].x; -y = vertex[i].y-vertex[j].y; -DISTANCE[I][J] = sqrt (x*x + y*y); -Distance[j][i] =Distance[i][j]; in } - } tosum =0; +Start =0; -cnt[0] =true; thememcpy (D, distance[0],sizeof(D)); * for(intI=1; i<n; ++i) $ {Panax Notoginseng for(intj=1; j<n; ++j) - { the if(!cnt[j] && Distance[start][j] <D[j]) +D[J] =Distance[start][j]; A } theMintag =0; + for(intj=1; j<n; ++j) - { $ if(Cnt[j]) $ Continue; - if(D[j] <D[mintag]) -Mintag =J; the } -Cnt[mintag] =true;WuyiSum + =D[mintag]; theStart =Mintag; - } Wumemset (CNT,0,sizeof(CNT)); -printf"%.2lf\n", sum); About } $}
POJ 2560 Freckles (minimum spanning tree)