HDOJ 题目1162 Eddy's picture(最小生成树)
来源:互联网 发布:如何制作淘宝网页 编辑:程序博客网 时间:2024/05/21 06:28
Eddy's picture
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6855 Accepted Submission(s): 3466
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?
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.
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
31.0 1.02.0 2.02.0 4.0
Sample Output
3.41
Author
eddy
Recommend
JGShining | We have carefully selected several similar problems for you: 1301 1217 1142 1856 1598
ac代码
#include<stdio.h>#include<string.h>#include<math.h>#define INF 0xfffffffint v[200];double map[200][200];int main(){int n;while(scanf("%d",&n)!=EOF){int i,j,flag;double x[500],y[500],sum=0,min;memset(v,0,sizeof(v));for(i=0;i<n;i++)scanf("%lf%lf",&x[i],&y[i]);for(i=0;i<n;i++){for(j=i+1;j<n;j++){map[i][j]=map[j][i]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));}}v[0]=1;for(i=1;i<n;i++){min=INF;flag=-1;for(j=0;j<n;j++){if(!v[j]&&map[0][j]<min){min=map[0][j];flag=j;}}v[flag]=1;sum+=map[0][flag];for(j=0;j<n;j++){if(!v[j]&&map[0][j]>map[flag][j])map[0][j]=map[flag][j];}}printf("%.2lf\n",sum);}}
0 0
- HDOJ 题目1162 Eddy's picture(最小生成树)
- HDOJ 1162 Eddy's picture(最小生成树 - kruskal)
- HDOJ 1162 Eddy's picture(最小生成树)
- HDOJ 1162:Eddy's picture 求解最小生成树
- hdoj 1162 Eddy's picture 【最小生成树】
- hdoj 1162 Eddy's picture(最小生成树)
- HDOJ 1162 Eddy's picture(最小生成树--kruskal)
- HDOJ 1162 Eddy's picture(最小生成树prim算法)
- hdoj 1162 Eddy's picture【最小生成树】
- HDOJ 1162 Eddy's picture 最小生成树 Kruscal && Prim
- HDOJ 1162 Eddy's Picture (最小生成树)
- hdoj--1162--Eddy's picture(最小生成树)
- hdoj 1162 Eddy's picture【最小生成树 kruskal && prim】
- HDOJ 1162 Eddy's picture 最小生成树
- Eddy's picture(最小生成树)
- HDOJ 1198 Eddy's picture 最小生成树
- hdu 1162 Eddy's picture(最小生成树)
- hdu 1162 Eddy's picture(基础最小生成树)
- 90后架构师崛起(伪)?基于resin3标准版的集群实现
- Task Flow使用指南之九:Remote TaskFlow
- 黑马程序员_关于java抽象类abstract自我总结
- 嵌入式linux自学过程
- String,StringBuffer与StringBuilder的区别??
- HDOJ 题目1162 Eddy's picture(最小生成树)
- 使用ADF Mobile开发Android手机On-Device应用
- 车牌识别系统源代码
- LeetCode:2.1.6 Longest Consecutive Sequence
- c语言中的字符数组与字符串
- 页面常用布局模板之一:Flow
- (Android review)打开Activity返回结果
- 正则表达式匹配包括换行符的所有字符
- Java反射之Class,Constructor,Field