HDU ACM 1162 Eddys picture(MST)

Eddy’s picture

Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4521Accepted Submission(s): 2241

Problem Description

Eddy begins to like painting pictures recently ,he is sure of himself to become a painter.Every day Eddy draws pictures in his small room, and he usually puts out his newest pictures to let his friends appreciate. but the result it can be imagined, the friends are not interested in his picture.Eddy feels very puzzled,in order to change all friends ‘s view to his technical of painting pictures ,so Eddy creates a problem for the his friends of you.Problem descriptions as follows: Given you 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?

Input

The first line contains 0 < n <= 100, the number of point. For each point, a line follows; each following line contains two real numbers indicating the (x,y) coordinates of the point.Input contains multiple test cases. Process to the end of file.

Output

Your program prints a single real number to two decimal places: the minimum total length of ink lines that can connect all the points.

Sample Input

3

1.0 1.0

2.0 2.0

2.0 4.0

Sample Output

3.41

Author

eddy

Recommend

JGShining

#include<stdio.h>#include<string.h>#include<math.h>double path[102][102];int flag[102];double closedge[102];double max;double cnt;typedef struct{double x, y;}input;input temp[102];double calculate(double x1, double y1, double x2, double y2){sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}double CreatMST(int n){int i, j, x;double k;flag[0] = 1;for(i=1; i<n; ++i)closedge[i] = path[0][i];for(i=1; i<n; ++i){k = max, x = 1;for(j=1; j<n; ++j)if(!flag[j] && closedge[j] < k)x = j, k = closedge[j];flag[x] = 1;cnt += k;for(j=1; j<n; ++j)if(!flag[j] && closedge[j] > path[x][j])closedge[j] = path[x][j];}return cnt;}int main(){int i, j, k, t, x, y, n, m;, &n) != EOF){max = 0;cnt = 0;memset(temp, 0, sizeof(input)*102);memset(flag, 0, sizeof(flag));memset(closedge, 0, sizeof(closedge));memset(path, 0, sizeof(double)*102*102);for(i=0; i<n; ++i)scanf(, &temp[i].x, &temp[i].y);(i=0; i<n; ++i)for(j=0; j<n; ++j){path[i][j] = calculate(temp[i].x, temp[i].y, temp[j].x, temp[j].y);if(max < path[i][j]) max = path[i][j];}printf(, CreatMST(n));}return 0;}

解题报告:1y

最小生成树不会叫你就写一个函数就行了。

,网站空间,香港空间,香港虚拟主机比天才难得,许多天赋差的人经过过勤学苦练也取得了很大的成功。

HDU ACM 1162 Eddys picture(MST)

相关文章:

你感兴趣的文章:

标签云: