Eddy's picture

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

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:  1301 1213 1116 1269 1198 
 

最小生成树入门题:

 //0MS     384K    1215B     G++
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
struct point{
double x,y;
}p[];
struct node{
int u,v;
double d;
}t[];
int set[],n;
int cmp(const void*a,const void*b)
{
return (*(node*)a).d>(*(node*)b).d?:-;
}
int find(int x)
{
if(set[x]!=x) set[x]=find(set[x]);
return set[x];
}
int merge(int a,int b)
{
int x=find(a);
int y=find(b);
if(x!=y){
set[x]=y;
return ;
}
return ;
}
double kruskal()
{
double ans=;
for(int i=;i<n*n;i++)
if(merge(t[i].u,t[i].v))
ans+=t[i].d;
return ans;
}
double dis(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int main(void)
{
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<=n;i++) set[i]=i;
for(int i=;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
int k=;
for(int i=;i<n;i++)
for(int j=;j<n;j++){
t[k].u=i;
t[k].v=j;
t[k].d=dis(p[i],p[j]);
k++;
}
qsort(t,n*n,sizeof(t[]),cmp);
printf("%.2lf\n",kruskal());
}
return ;
}

hdu 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. 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 ...

  4. HDU 1162 Eddy's picture

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

  5. hdu 1162 Eddy's picture (prim)

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

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

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

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

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

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

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

  9. 题解报告:hdu 1162 Eddy's picture

    Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to become ...

随机推荐

  1. 长沙Uber司机奖励政策(8月24日到8月30日)

    本周奖励(8月24日到8月30日) 滴滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://w ...

  2. LeetCode:46. Permutations(Medium)

    1. 原题链接 https://leetcode.com/problems/permutations/description/ 2. 题目要求 给定一个整型数组nums,数组中的数字互不相同,返回该数 ...

  3. Spring Boot中使用缓存

    Spring Boot中使用缓存 随着时间的积累,应用的使用用户不断增加,数据规模也越来越大,往往数据库查询操作会成为影响用户使用体验的瓶颈,此时使用缓存往往是解决这一问题非常好的手段之一. 原始的使 ...

  4. C 计算时间差

    #include <stdio.h>int main(){ //新建四个变量 la 代表小时 kc代表时间 int l,k,a,c; //输入 两个时间 scanf("%d %d ...

  5. python 打包

    一.下载 pip install Pyinstaller 二.使用Pyinstaller 1.使用下载安装的方式安装的Pyinstaller打包方式 将需要打包的文件放在解压得到的Pyinstalle ...

  6. JavaScript 数组操作方法 和 ES5数组拓展

    JavaScript中数组有各种操作方法,以下通过举例来说明各种方法的使用: 数组操作方法 push 在数组最后添加一个元素 var arr=[3,4,5,6] console.log(arr) // ...

  7. Python基础 之 list类-列表

    list类-列表 一.list类的基本属性 1. 列表格式 li = [1, 12, 9, ", 10], "even"], "root", True ...

  8. 加密SecurityHelper

    接下来给大家分享一下我用的加密helper,现在只用的md5加密的方法,网上很多方法找到的时候加密完了会变成乱码,这样对于密码这种字段保存的时候就会出错.其实只需要把加密完的byte字节转化成16位就 ...

  9. ubuntu server guide 学习笔记

    1. 软件包 1.1. dpkg dpkg -l dpkg -l | grep apache2 dpkg -L ufw dpkg -S /etc/host.conf dpkg -i zip_3.0-4 ...

  10. 简析@Resource 和 @Autowired的区别

    @Autowird @Autowird 属于spring框架,默认使用类型(byType)进行注入,例如下面代码: @Autowired public IUserService userService ...