#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. ScaleYViewPager

    https://github.com/eltld/ScaleYViewPager

  2. LZMA C# SDK 结合 UPK 打包压缩 多目录 Unity3d实例

    上篇  LZMA C# SDK 子线程压缩与解压缩 Unity3d实例  讲了怎样使用 LZMA C# SDK 来对文件进行压缩与解压,当中提到 对于多目录能够先打包成 UPK 然后再 LZMA 压缩 ...

  3. 【IOS工具类】IOS9的CoreSpotlight(OC语言)

    什么是CoreSpotlight?就是在IOS9下.让用户在下拉的搜索页面里能够搜索到你的应用. #import <Foundation/Foundation.h> @interface ...

  4. 翻译:A Tutorial on the Device Tree (Zynq) -- Part V

    A Tutorial on the Device Tree (Zynq) -- Part V Application-specific data 之前提过,设备树中是一些特殊信息,这样一个驱动可以管理 ...

  5. mac下配置eclipse的maven环境

    转自:http://www.cnblogs.com/yqskj/archive/2013/03/30/2990292.html 1.下载maven的bin包,解压,配置到环境变量里面去 1). 首先到 ...

  6. day 18 面向对象的 继承

    一.概念性知识 面向对象的三大特征:     继承,多态,封装 继承是创建新类的一种方法,在python中,新建的类可以继承一个或多个父类,父类称作基类或超类,新建的类又称作派生类或子类. 继承的好处 ...

  7. Python 中的字节与字节数组

    Python 中的字节与字节数组 - Python - 伯乐在线 http://python.jobbole.com/84839/

  8. PPAPI与Browser间使用AsyncIPC通信

    採用AsyncIpc这个项目(https://github.com/hicdre/AsyncIpc).来完毕PPAPI Plugin进程与Browser进程的通信. foruok原创.如需转载请关注f ...

  9. rails find find_by where

    find根据id进行查询,像Product.find(3),查询语句是Product Load (0.1ms) SELECT "products".* FROM "pro ...

  10. Windows下VMware虚拟机使用Centos,Docker方式安装openstf的小坑

    今天使用docker方式安装openstf碰到了一小坑,坑了我半天.特此记录! docker方式安装stf就不说了,网上教程一大把. 但是... 安装完之后.进入web控制界面,手机连接的好好的.但硕 ...