Eddy's picture

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 8562    Accepted Submission(s): 4339
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   |   We have carefully selected several similar problems for you:  1217 1142 1213 1325 1856 

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
int x,y;
double val;
}edge[100100];
double x[10010],y[10010];
int cmp(node s1,node s2)
{
if(s1.val<s2.val)
return 1;
return 0;
}
int pre[10010];
void init()
{
for(int i=0;i<10010;i++)
pre[i]=i;
}
int find(int x)
{
return pre[x]==x?x:pre[x]=find(pre[x]);
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<n;i++)
scanf("%lf%lf",&x[i],&y[i]);
int cnt=0;
init();
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==j) continue;
edge[cnt].x=i;
edge[cnt].y=j;
edge[cnt++].val=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}
}
sort(edge,edge+cnt,cmp);
double sum=0;
for(int i=0;i<cnt;i++)
{
int fx=find(edge[i].x);
int fy=find(edge[i].y);
if(fx!=fy)
{
sum+=edge[i].val;
pre[fx]=fy;
}
}
printf("%.2lf\n",sum);
}
return 0;
}

hdoj--1162--Eddy's picture(最小生成树)的更多相关文章

  1. hdu 1162 Eddy's picture(最小生成树算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...

  2. HDU 1162 Eddy's picture (最小生成树)(java版)

    Eddy's picture 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 ——每天在线,欢迎留言谈论. 题目大意: 给你N个点,求把这N个点 ...

  3. hdoj 1162 Eddy's picture

    并查集+最小生成树 Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  4. hdu 1162 Eddy's picture (最小生成树)

    Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  5. hdu 1162 Eddy's picture (Kruskal 算法)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...

  6. HDU 1162 Eddy's picture

    坐标之间的距离的方法,prim算法模板. Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32 ...

  7. hdu 1162 Eddy's picture (prim)

    Eddy's pictureTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  8. HDU 1162 Eddy's picture (最小生成树 prim)

    题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...

  9. HDU 1162 Eddy's picture (最小生成树 普里姆 )

    题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...

  10. hdu 1162 Eddy's picture(最小生成树,基础)

    题目 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<string.h> #include <ma ...

随机推荐

  1. python简易版学生管理系统

    #coding=utf- def showInfo(): print("**************") print(" 学生管理系统") print(&quo ...

  2. 【正则表达式】从json数组中抽取id列表

    有如下数组,要从中取出id: "[\"3812662409\",\"3812633637\",\"3812627686\",\&q ...

  3. Java基础1一环境配置

    1.下载JDK:http://www.oracle.com/technetwork/java/javase/downloads/index.html 2.JDK安装:直接点击下一步,直到完成.注:默认 ...

  4. JDK和Cglib实现动态代理实例及优缺点分析

    Spring AOP使用的核心技术是动态代理,说到动态代理就不得不和设计模式中的代理模式联系起来,通过代理模式我们可以对目标类进行功能增强,在某个方法的执行前后增加一些操作,例如计算方法执行效率.打印 ...

  5. [原创]一道基本ACM试题的启示——多个测试用例的输入问题。

    Problem Description 输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离. Input 输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数 ...

  6. WinRAR 5.60 无广告正式版

    首先明确WinRAR唯一的官网是这个 https://www.rarlab.com/ 其余的都不要相信. 现在的问题是:不要脸的中国代理强行捆绑广告:即使你花钱注册同样要面对弹窗广告!这就不可接受了! ...

  7. Online ML那点事>-

    一:译自wiki:    KeyWord:标签反馈; Survey: online machine learning is a model of induction that learns one i ...

  8. Angular ui-router的常用配置参数详解

    一.$urlRouterProvider服务 $urlRouterProvidfer负责监听$location,当$location变化时,$urlRouterProvider将在规则列表中查找匹配的 ...

  9. 模拟一个简单的基于tcp的远程关机程序(转)

    最近在学习unix网络编程,现在正在学习tcp的通信.其实,只要建立起了tcp通信,操作远端的计算机就不是什么问题了.正向telnet一样,也是基于tcp/IP协议的.所以这个实验,也算是对telne ...

  10. C# word生成html

    引入 Aspose.Words public void ConvertToHtml(string wordPath, string savaPath) { try { Aspose.Words.Doc ...