#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. mt7620 wifi driver

    <*> Ralink RT2860 802.11n AP support [*] LED Support [*] WSC (WiFi Simple Config) [*] WSC 2.0( ...

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

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

  3. 一个动态库连续注册的windows脚本regsvr32

    cmd ->for %1 in (%windir%\system32\*.dll) do regsvr32.exe /s %1

  4. 流媒体开发之开源项目live555---live555 server 编译 包括更改帧率大小

    由于要测试8148解码器的性能,需要搭建不同帧率25fps - >30fps,宏块大小defualt 100 000 -> 200 000不同大小的h264码流,所以就需要编译改动的liv ...

  5. angularjs开发常见问题-2(angularjs内置过滤器)

    在angular中内置了几个经常使用的filter,能够简化我们的操作. 过滤器使用 '|' 符号,概念有点相似于linux中的管道. 1.filter (过滤) filter能够依据条件过滤数据.样 ...

  6. using the flume-ng-sql-source plugin to push data from Mysql DB to Spark

    org.apache.flume.EventDeliveryException while running flume and sending data to spark · Issue #21 · ...

  7. Java中数组复制的几种方式以及数组合并

    1.Object.clone() 简单直接,只能对源数组完整地复制 2.Arrays.copyOf(T[] original, int newLength) 可以只复制源数组中部分元素,但复制的起始位 ...

  8. (linux)MMC 卡驱动分析

    最近花时间研究了一下 MMC 卡驱动程序,开始在网上找了很多关于 MMC 卡驱动的分析文章,但大都是在描述各个层,这对于初学者来讲帮助并不大,所以我就打算把自己的理解写下来,希望对大家有用.个人觉得理 ...

  9. POJ1077 Eight —— 经典的搜索问题

    题目链接:http://poj.org/problem?id=1077 Eight Time Limit: 1000MS   Memory Limit: 65536K Total Submission ...

  10. [SHOI 2015] 脑洞治疗仪

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=4592 [算法] 对于操作1 , 我们首先查询区间[l0 , r0]中有多少个1 , ...