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. java编译器和java解释器、JVM

    作用: JVM:JVM有自己完善的硬件架构,如处理器.堆栈(Stack).寄存器等,还具有相应的指令系统(字节码就是一种指令格式).JVM屏蔽了与具体操作系统平台相关的信息,使得Java程序只需要生成 ...

  2. 【JAVA练习】- 给定精度求圆周率π

    给定一个精度求圆周率π的近似值 给定公式:π/4=1-1/3+1/5-1/7+1/9-... public static void main(String[] args) { System.out.p ...

  3. cannot connect to host的解决办法

    作者:朱金灿 来源:http://blog.csdn.net/clever101 下午更新源码,出现下面的错误: 通过ping来测试svn服务器的连接,发现可以连接得通,于是猜测可以服务器的svn服务 ...

  4. DHCP 和 MDT 分开服务器的设置方法

    DHCP设置 043:供应商特定信息:01 04 00 00 00 00 FF 060:PXEClient:PXEClient 066:启动服务器主机名:IP 067:启动文件名:\Boot\x86\ ...

  5. Verification之PSL之intro

    1 PSL - Property specification language 1.1 Property - Characteristics of the designs/verification e ...

  6. Java_Web之神奇的Ajax

    为什么使用Ajax? 无刷新:不刷新整个页面,只刷新局部 无刷新的好处 提供类似C/S的交互效果,操作更方面 只更新部分页面,有效利用带宽   什么是Ajax?   XMLHttpRequest常用方 ...

  7. 读书笔记「Python编程:从入门到实践」_5.if语句

    5.1 一个简单示例 cars = ['audi', 'bmw', 'subaru', 'toyota'] for car in cars: if car == 'bmw': print(car.up ...

  8. [Jxoi2012]奇怪的道路 题解(From luoguBlog)

    题面 状压好题 1<= n <= 30, 0 <= m <= 30, 1 <= K <= 8 这美妙的范围非状压莫属 理所当然地,0和1代表度的奇偶 dp[i][j ...

  9. logging模块-logging.basicConfig、logger.setLevel、handler.setLevel优先级

    logging.basicConfig < handler.setLevel < logger.setLevel 1.脚本中没有配置logger.setLevel会使用handler.se ...

  10. 怎么在阿里云搭建一个WordPress博客(超详细教程)

    想以正确的方式启动一个 WordPress 博客吗?我知道,这可能是一个令人恐惧的想法 -- 其实你并不孤单.但是,在帮助很多用户创建博客之后,我决定编写一份详细的指南,让任何没有技术知识的人都能拥有 ...