#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std; int n, m;
int f[]; struct node
{
int u, v;
double w;
}map[]; int getf(int a)
{
if (f[a] == a)
{
return a;
} f[a] = getf(f[a]);
return f[a];
} void merge(int a, int b)
{
int x = getf(a);
int y = getf(b); if (x != y)
f[y] = x;
} void init()
{
for (int i = ; i <= n; i++)
f[i] = i;
} bool cmp(node a, node b)
{
return a.w < b.w;
} double kura()
{
double res = ;
sort(map, map + m, cmp); for (int i = ; i < m; i++)
{
if (getf(map[i].u) != getf(map[i].v))
{
merge(map[i].u, map[i].v);
res += map[i].w;
}
}
return res;
} double a[][]; int main()
{
while (scanf("%d", &n) != EOF)
{
m = n*(n - );
for (int i = ; i <= n; i++)
scanf("%lf %lf", &a[i][], &a[i][]); int k = ;
for (int i = ; i <= n; i++)
{
for (int j = i + ; j <= n; j++)
{
map[k].u = i;
map[k].v = j;
map[k].w = sqrt(abs(pow(a[j][] - a[i][], ) + pow(a[j][] - a[i][], )));
k++;
}
}
init();
printf("%.2lf\n", kura());
} return ;
}

hdu1162 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. hdu Eddy's picture (最小生成树)

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

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

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

  4. hdu 1162 Eddy's picture(最小生成树,基础)

    题目 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<string.h> #include <ma ...

  5. HDU 1162 Eddy's picture (最小生成树 prim)

    题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...

  6. HDU 1162 Eddy's picture (最小生成树 普里姆 )

    题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...

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

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

  9. 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. 利用NSMutableAttributedString实现label上字体大小颜色行间距的改变

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.si ...

  2. 安卓动态逆向分析工具--Andbug&Androguard

    工具使用方法: 转自: http://bbs.pediy.com/showthread.php?t=183412 https://testerhome.com/topics/3542 安装andbug ...

  3. 多媒体开发之---h264快速运动估计算法

    #include "stdio.h"#include "stdlib.h"#include "malloc.h"#include " ...

  4. Writing a Simple YARN Application 从hadoop生态抽出yarn ,单独使用yarn

    Apache Hadoop 2.9.1 – Hadoop: Writing YARN Applications https://hadoop.apache.org/docs/current/hadoo ...

  5. firefox 45 版本

    在做项目的时候,发现45版本的firefox浏览器.声明函数要放在调用者的上方.而firefox的47,48版本则没有这种情况发生.

  6. (C)inline关键字

      背景(C&C++中) 一.inline关键字用来定义一个类的内联函数,引入它的主要原因是用它替代C中表达式形式的宏定义. 表达式形式的宏定义一例:#define ExpressionNam ...

  7. 一步一步学Silverlight 2系列(15):数据与通信之ASMX

    概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...

  8. nginx最简单的网站配置:单主机+静态文件

    1.域名绑定主机:新建一个A记录,将www的子域名绑定到主机的ip上:2.主机的nginx设置监听端口,绑定域名,修改网站根目录路径和默认首选文件:/etc/nginx/conf.d 这个目录中新建一 ...

  9. limit的用法

    limit子句可以用于强制select语句返回指定的记录数.limit接受一个或两个数字参数,参数必须是整数常量.如果给定两个参数,第一个参数指定第一个返回记录行的偏移量,第二个参数指定返回记录行的最 ...

  10. java服务器端断点续传

    Servlet Java代码 复制代码 收藏代码 import java.io.BufferedOutputStream; import java.io.File; import java.io.IO ...