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. 让PictureBox支持URL显示图片

    [ToolboxItem(true)] public class PictureBoxURL : PictureBox { private string _url = ""; pu ...

  2. centos升级glibc(升级到2.14版)

    1.下载源码包 到http://ftp.gnu.org/gnu/glibc/下载glibc-2.14.tar.xz 2.解压 tar glibc-2.14.tar.gz 3.创建build目录 cd ...

  3. 合并文件夹里多个excel

    Sub 合并当前目录下所有工作簿的全部工作表() Dim MyPath, MyName, AWbName Dim Wb As workbook, WbN As String Dim G As Long ...

  4. Manual——Test (翻译1)

    LTE Manual ——Logging(翻译) (本文为个人学习笔记,如有不当的地方,欢迎指正!) 1.17.3 Testing framework(测试框架)   ns-3 包含一个仿真核心引擎. ...

  5. 最新榜单!消金企业TOP10,数据、风控、催收服务方TOP5

    最新榜单!消金企业TOP10,数据.风控.催收服务方TOP5 布谷TIME2016-12-15 17:47:59消费 风控阅读(164)评论(0) 声明:本文由入驻搜狐公众平台的作者撰写,除搜狐官方账 ...

  6. OO的五大原则是指SRP、OCP、LSP、DIP、ISP。

    OO的高层原则,面向对象设计的基本原则 设计模式之六大原则--开闭原则(OCP) 设计模式之六大原则--迪米特法则(LoD,LKP) 设计模式之六大原则--接口隔离原则(ISP) 设计模式之六大原则- ...

  7. ubuntu 编译源码坏境配置

    git checkout -b newlocal origin/q01v31source build/envsetup.shlunch msm8916_32-usermake -j4 make -j4 ...

  8. 转:深入浅出UML类图(具体到代码层次)

    深入浅出UML类图 作者:刘伟 ,发布于:2012-11-23,来源:CSDN   在UML 2.0的13种图形中,类图是使用频率最高的UML图之一.Martin Fowler在其著作<UML ...

  9. SQL Server Reporting Service(SSRS) 第一篇 我的第一个SSRS例子

    很早就知道SQL SERVER自带的报表工具SSRS,但一直没有用过,最近终于需要在工作中一展身手了,于是我特地按照自己的理解做了以下总结: 1. 安装软件结构 SSRS全称SQL Server Re ...

  10. OneProxy安全策略

    set gaccess <groupname> <level> 注意事项– 级别0:没有限制– 级别1:禁止DDL– 级别2:必须要有where条件– 级别4:禁止Delete ...