#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. Ubuntuserver版安装

          近期因为工作的须要.又一次部署server.安装了Ubuntuserver版本号,依据当时遇到的一些问题,整理了下,为方便以后的使用做个记录.       因为直接安装server端.无法 ...

  2. 几个简单的程序看PHP的垃圾回收机制

    每一种计算机语言都有自己的自动垃圾回收机制,让程序员不必过分关心程序内存分配,php也不例外,但是在面向对象编程(OOP)编程中,有些对象需要显式的销毁,防止程序执行内存溢出. 一.PHP 垃圾回收机 ...

  3. 【Java架构学习】Model1和Model2讨论

    在Java的学习中.这两个词的频率出现的非常高.那就是Model1和Model2.那么到底什么是Model1,什么是Model2呢?我们是不是又非常自然接受这两个概念.可是不知道其所以然呢?今天我们就 ...

  4. LeetCode(3)题解: Longest Palindromic Substring

    https://leetcode.com/problems/longest-palindromic-substring/ 题目: Given a string S, find the longest ...

  5. install build tools 25.0.2 and sync the project

    install build tools 25.0.2 and sync the project in android studio bundle.gradle,将buildToolsVersion修改 ...

  6. noip2016前的话[漫谈]

    今天是11月15日,离noip2016还剩三天: 今年我也是高二了,回首一下去年的时光,真的仿佛仍在昨天,我甚至现在还清楚的记得,当年那次我们做的每一件事: 星期五,回去与室友告别,得到了祝愿,乘公交 ...

  7. Android系统设置Android adb 开关的方法【转】

    本文转载自:http://www.wxtlife.com/2015/11/24/Android-set-adb-status/ 想第一时间获取我的最新文章,请关注公众号: 技术特工队 在整机系统开发中 ...

  8. 多线程、死锁、线程安全、同步方法、代码块、休眠、守护线程、Thread、Runnable(二十三)

    1.多线程的引入 * 1.什么是线程 * 线程是程序执行的一条路径, 一个进程中可以包含多条线程 * 多线程并发执行可以提高程序的效率, 可以同时完成多项工作* 2.多线程的应用场景 * 红蜘蛛同时共 ...

  9. 推箱子 hdu1254

    推箱子 1  http://acm.hdu.edu.cn/showproblem.php?pid=1254 推箱子 2  http://acm.hzau.edu.cn/problem.php?id=1 ...

  10. GDUT 积木积水 2*n 时间复杂度

    题意 Description 现有一堆边长为1的已经放置好的积木,小明(对的,你没看错,的确是陪伴我们成长的那个小明)想知道当下雨天来时会有多少积水.小明又是如此地喜欢二次元,于是他把这个三维的现实问 ...