HDU1162-Eddy's picture
2016-09-10 21:08
281 查看
Eddy's picture
Time Limit: 2000/1000 MS (Java/Others) Memory Limit:65536/32768 K (Java/Others)
Total Submission(s): 9491 Accepted Submission(s): 4789
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
#include <iostream> #include <string.h> #include <stdio.h> #include <math.h> using namespace std; double map[105][105]; double dis[105]; int visit[105]; const int INF=0x3f3f3f3f; double x[105],y[105]; int main() { int n; while(~scanf("%d",&n)) { for(int i=1; i<=n; i++) scanf("%lf %lf",&x[i],&y[i]); for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { if(i==j) map[i][j]=0; else map[i][j]=INF; } } double p; for(int i=1; i<=n; i++) { for(int j=i+1; j<=n; j++) { p=1.0*sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])); map[i][j]=map[j][i]=p; } } memset(visit,0,sizeof visit); double sum=0; visit[1]=1; for(int i=1; i<=n; i++) dis[i]=map[1][i]; for(int i=1; i<n; i++) { double mi=INF; int k=-1; for(int j=1; j<=n; j++) if(!visit[j]&&dis[j]<mi) mi=dis[j],k=j; if(k!=-1) { sum+=mi; visit[k]=1; for(int j=1; j<=n; j++) if(!visit[j]&&map[k][j]<dis[j]) dis[j]=map[k][j]; } } printf("%.2lf\n",sum); } return 0; }
相关文章推荐
- hdu1162-Eddy's picture
- hdu1162-Eddy's picture
- HDU 1162 Eddy's picture
- Hdu 1162 - Eddy's picture
- HDU 1162 Eddy's picture
- (step 6.1.9)hdu 1162(Eddy's picture——最小生成树)
- HDU1162-Eddy's picture-最小生成树(prim算法模板)
- hdu 1162 Eddy's picture
- 杭电Hdu 1162 Eddy's picture
- HDU-1162-Eddy's picture
- HDU 1162 Eddy's picture 最小生成树
- hdu 1162 Eddy's picture
- HDU 1162 Eddy's picture【最小生成树,Prime算法+Kruskal算法】
- hdu 1162 Eddy's picture
- hdu-1162 Eddy's picture
- HDU 1162 Eddy's picture 最小生成树
- 最小生成树(模板题)Eddy's picture HDU - 1162
- HDU 1162 Eddy's picture(点连通:最小生成树)
- hdu-1162-Eddy's picture
- hdu1162 Eddy's picture 最小生成树 prim