Eddy's picture

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

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
 #include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int father[];
double s;
struct ssss
{
double a,b;
}ss[];
struct dddd
{
int a,b;
double x;
}dd[];
int Find(int a)
{
return a==father[a]?a:father[a]=Find(father[a]);
}
void Union(int i)
{
int a=Find(dd[i].a),b=Find(dd[i].b);
if(a!=b)father[a]=b,s+=dd[i].x; //只有没有连通的才能进行这一步,所以每次都是需要连通的最短距离
}
bool cmp(const dddd &a,const dddd &b)
{
return a.x<b.x;
}
int main (void)
{
int n,i,j,k,l;
while(cin>>n)
{
for(i=;i<n;i++)
cin>>ss[i].a>>ss[i].b;
for(i=;i<;i++)father[i]=i; //初始化
for(i=l=;i<n;i++)
for(j=i+;j<n;j++)
{
dd[l].a=i,dd[l].b=j;
double x=ss[i].a-ss[j].a,y=ss[i].b-ss[j].b;
dd[l++].x=sqrt(x*x+y*y); //老规矩,把距离存两点一起
}
sort(dd,dd+l,cmp);
for(i=,s=;i<l;i++)
Union(i); //并起来
printf("%.2f\n",s);
}
return ;
}

AC代码

杭电--1162--Eddy's picture--并查集的更多相关文章

  1. 杭电OJ——1198 Farm Irrigation (并查集)

    畅通工程 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可 ...

  2. 【杭电OJ3938】【离线+并查集】

    http://acm.hdu.edu.cn/showproblem.php?pid=3938 Portal Time Limit: 2000/1000 MS (Java/Others)    Memo ...

  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(最小生成树算法)

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

  5. hdoj 1162 Eddy's picture

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

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

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

  7. HDU 1162 Eddy's picture

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

  8. 杭电1162Eddy&#39;s picture

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

  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 (prim)

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

随机推荐

  1. 在 ASP.NET MVC 中使用 HTML Helpers 的那些事

    在 ASP.NET MVC 中使用 HTML Helpers 方法,可以返回得到标准的 HTML 标签,就像 <input>.<button> 或者 <img> 等 ...

  2. php保留键随机打乱数组顺序

    最近遇到一个需求,把一个数组随机打乱顺序,我们可以用php的shuffle函数,但是这个函数会把数组的键清空建立新的键,那么我们若想保留键只需要利用shuffle函数再做一下处理就可以了.可以自定义一 ...

  3. jdbc.properties各种数据库连接配置

    # HSQLDB  #jdbc.driverClassName=org.hsqldb.jdbcDriver #jdbc.url=jdbc:hsqldb:hsql://localhost:9001/bo ...

  4. Cocos2d-x 核心概念 - 坐标系(UI.OpenGL.世界坐标系.模型坐标系)

    UI坐标系与OpenGL坐标系 UI坐标就是Android和IOS等应用开发时候使用的二维坐标系,原点在左上角 OpenGL坐标是三维坐标,由于Cocos2d-x Lua 底层采用OpenGL渲染,因 ...

  5. Remoting&WebService的区别之处

    Remoting与Web Services的区别是:(1)既支持TCP信道又支持HTTP信道,传输速度快(2)即可传输XML的SOAP包又可传输二进制流,效率高(3)Remoteing主要用于C/S结 ...

  6. webstorm自动编译typescript

    http://bbs.egret.com/thread-1752-1-1.html http://bbs.egret.com/thread-1912-1-1.html

  7. RDLC隔行变色的实现

    在RDLC设计页面设置行属性中的Background为: =IIF((RowNumber(Nothing)) Mod 2 =1,"Transparent","#F6FAF ...

  8. SPSS数据分析-时间序列模型

    我们在分析数据时,经常会碰到一种数据,它是由时间累积起来的,并按照时间顺序排列的一系列观测值,我们称为时间序列,它有点类似于重复测量数据,但是区别在于重复测量数据的时间点不会很多,而时间序列的时间点非 ...

  9. [HTML/HTML5]8 使用表格

    8.1  创建基本的表格结构 8.1.1  表格结构 HTML表格包含4种基本元素: table:在HTML中table元素是一个容器,其中包含用于创建表格的其它的元素: tr:表示表格中的行,开始标 ...

  10. js制作简单的计算器

    学着做了一个简单的计算器!记录记录!哈哈 <!DOCTYPE html> <html> <head> <title>简单的计算器</title&g ...