Eddy's picture

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 8   Accepted Submission(s) : 3
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<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int pre[101];
void itin()
{
for(int i=0;i<101;i++)
pre[i]=i;
}
struct point
{
float x,y;
}p[100];
struct dis
{
int u,v;
float val;
}d[100010];
int cmp(dis n1,dis n2)
{
if(n1.val<n2.val)
return 1;
return 0;
}
int find(int x)
{
while(x!=pre[x])
x=pre[x];
return x;
}
bool join(int x,int y)
{
int fx=find(x);
int fy=find(y);
if(fx!=fy)
{
pre[fx]=fy;
return true;
}
return false;
}
int main()
{
int t;
while(scanf("%d",&t)!=EOF)
{
itin();
int i,j;
memset(p,0,sizeof(p));
float sum=0;
for(i=0;i<t;i++)
scanf("%f%f",&p[i].x,&p[i].y);
int cnt=0;
for(i=0;i<t;i++)
for(j=i+1;j<t;j++)
{
float dist=sqrt((p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y));
d[cnt].u=i;
d[cnt].v=j;
d[cnt++].val=dist;
}
sort(d,d+cnt,cmp);
/*for(i=0;i<cnt;i++)
printf("%f ",d[i].val);
printf("\n");*/
for(i=0;i<cnt;i++)
{
if(join(d[i].u,d[i].v))
{
sum+=d[i].val;
//printf("%f\n",sum);
} }
printf("%.2f\n",sum);
}
return 0;
}

Eddy's picture的更多相关文章

  1. HDUOJ-----(1162)Eddy's picture(最小生成树)

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

  2. hdoj 1162 Eddy's picture

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

  3. HDU 1162 Eddy's picture

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

  4. Eddy's picture(prime+克鲁斯卡尔)

    Eddy's picture Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tota ...

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

    Eddy's picture Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tota ...

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

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

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

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

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

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

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

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

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

随机推荐

  1. SQL SERVER 2000 如何提高大数据筛选GROUP BY 的效率

    数据库有83W条记录,本想计算20180101之后的每天赔付情况,故写了以下SQL语句: SELECT 起保时间,sum(赔付金额) as 日赔付 FROM maindata WHERE 起保时间&g ...

  2. 1C课程笔记分享_StudyJams_2017

    课程1C 概述 课程1C是创建一个生日贺卡应用的实践课程,所以本篇笔记分享主要记录个人的实践过程,此外分享一些比较零散的知识点. Drawable文件夹 Drawable文件夹是Android项目统一 ...

  3. Embedded之Stack之三

    Stack Overflow While stacks are generally large, they don't occupy all of memory. It is possible to ...

  4. MySQL--增删改查分页存储过程以及事务

    添加和修改写在一起了 可以用id判断添加和修改 和事务在一起编码 可以让代码更严谨 在这里简单的说一下事务的四大特性 事务四大特性之原子性:原子性是指事务是一个不可再分割的工作单位,事务中的操作要么都 ...

  5. centos6.5 安装redis自动启动

    1.安装需要的支持环境 在安装Redis之前首要先做的是安装Unix的 Tcl工具 ,如果不安装的话后期将无法对Redis进行测试.在后期执行make test的时候返回如下错误信息: You nee ...

  6. Day 2 语言元素

    1.变量和类型 在程序设计中,变量是一种存储数据的载体.计算机中的变量是实际存在的数据或者说是存储器中存储数据的一块内存空间,变量的值可以被读取和修改,这是所有计算和控制的基础.计算机能处理的数据有很 ...

  7. ext4的一些特性

    delalloc介绍 delalloc是ext4下的一个新特性,延迟分配技术Delay Allocation. 实现原理为: Buffer Write时数据会被保存到page cache中,但是系统并 ...

  8. win10环境下配置django+Apache2.4.38+python3.6项目

    1.)Apache-2.4.38-win64-vc15下载地址: https://www.apachelounge.com/download/VC14/ 解压httpd-2.4.38-win64-VC ...

  9. html第八节课

    导航 1.首先在<head>里面引用一个JQUERY的文件以用来制作鼠标点击动画效果(从网站上下载即可) 1 <script language="javascript&qu ...

  10. [jzoj5786]【NOIP2008模拟】观察 (dfs序+lca)

    传送门 Description infleaking十分愉快地走在路上, 因为经过10^9^9^9年后, 他得到了一个新技能--观察大法. 刚出来的infleaking就想要挑战自我. 为什么infl ...