杭电--1162--Eddy's picture--并查集
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 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 contains multiple test cases. Process to the end of file.
#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--并查集的更多相关文章
- 杭电OJ——1198 Farm Irrigation (并查集)
畅通工程 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可 ...
- 【杭电OJ3938】【离线+并查集】
http://acm.hdu.edu.cn/showproblem.php?pid=3938 Portal Time Limit: 2000/1000 MS (Java/Others) Memo ...
- 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 ...
- hdu 1162 Eddy's picture(最小生成树算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...
- hdoj 1162 Eddy's picture
并查集+最小生成树 Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- HDU 1162 Eddy's picture (最小生成树)(java版)
Eddy's picture 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 ——每天在线,欢迎留言谈论. 题目大意: 给你N个点,求把这N个点 ...
- HDU 1162 Eddy's picture
坐标之间的距离的方法,prim算法模板. Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32 ...
- 杭电1162Eddy's picture
Eddy's picture Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tota ...
- hdu 1162 Eddy's picture (最小生成树)
Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- hdu 1162 Eddy's picture (prim)
Eddy's pictureTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
随机推荐
- spring监听器
1,web.xml中配,因为tomcat启动web项目时先加载web.xml. 2,spring需要启动IOC容器才能为其他框架提供服务,spring是通过监听器来启动容器,初始化 这边启动它,也得告 ...
- Thread
问题:编写一个能提现多线程的例子?假设有t1,t2两个线程,如何保证t2线程在t1线程执行完后再执行? package cn.changb.thread; public class MyThread ...
- 个人博客作业Week2
一.是否需要有代码规范 这些规范都是官僚制度下产生的浪费大家的编程时间.影响人们开发效率, 浪费时间的东西. 我反驳这个观点,这些规范是成千上万的程序员在开发程序中总结出来的代码规范,他有助于我们的开 ...
- Python递归报错:RuntimeError: maximum recursion depth exceeded in comparison
Python中默认的最大递归深度是989,当尝试递归第990时便出现递归深度超限的错误: RuntimeError: maximum recursion depth exceeded in compa ...
- socket了解(转)
http://blog.chinaunix.net/uid-26000296-id-3758651.html http://blog.csdn.net/mengyafei43/article/deta ...
- spring aop 利用JoinPoint获取参数的值和方法名称
AspectJ使用org.aspectj.lang.JoinPoint接口表示目标类连接点对象,如果是环绕增强时,使用org.aspectj.lang.ProceedingJoinPoint表示连接点 ...
- mongo 相关命令
mongo导入数据: 1. 先进入找到mongo 安装目录 执行 ./mongo 进入mongo 2. mongorestore -u 用户名 -p 密码 -d 数据库 —drop 文件存在路径 显示 ...
- console
你所不知道的 Console 2016-12-19 ZHANGXIANGLIANG JavaScript 转自 https://segmentfault.com/a/119000000672160 1 ...
- RedHat下安装Telnet服务端及客户端远程连接配置
Telnet协议是TCP/IP协议族中的一员,是Internet远程登陆服务的标准协议和主要方式.它为用户提供了在本地计算机上完成远程主机工作的能力. 配置之前请确保网络连通,如防火墙影响连接,请先关 ...
- Linux中Screen命令使用方法
一.使用Screen创建一个Session screen -S sessionName 注:sessionName是要删除的session名字 二.结束一个Screen创建的session 1.首先使 ...