hdu1162 Eddy's picture 基础最小生成树
#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 基础最小生成树的更多相关文章
- HDUOJ-----(1162)Eddy's picture(最小生成树)
Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- hdu Eddy's picture (最小生成树)
Eddy's picture Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tota ...
- Eddy's picture(最小生成树)
Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- hdu 1162 Eddy's picture(最小生成树,基础)
题目 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<string.h> #include <ma ...
- HDU 1162 Eddy's picture (最小生成树 prim)
题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...
- HDU 1162 Eddy's picture (最小生成树 普里姆 )
题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...
- 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 (最小生成树)
Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- hdu 1162 Eddy's picture(最小生成树算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...
随机推荐
- Json实现异步请求(提交评论)
主要将代码粘贴,通过阅读代码理解当中的相关逻辑. html代码: <form id="form1" runat="server"> <p> ...
- sql注入攻防 以php+mysql为例
随着Web应用的高速发展和技术的不断成熟,对Web开发相关职位的需求量也越来越大,越来越多的人加入了Web开发的行列.但是由于程序员的水平参差不齐或是安全意识太低,很多程序员在编写代码时仅考虑了功能上 ...
- sanic官方文档解析之下载和Configuration
1,sanic框架是做什么的? sanic的官方网址:https://sanic.readthedocs.io/en/latest/ sanic框架是一个类似于flask框架的在Python3.5以上 ...
- Flume-ng-sdk源码分析
Flume 实战(2)--Flume-ng-sdk源码分析 - mumuxinfei - 博客园 http://www.cnblogs.com/mumuxinfei/p/3823266.html
- bind_ip
https://docs.mongodb.com/manual/reference/configuration-options/index.html 192.168.2.* --23T10:: I C ...
- redis的图形界面管理工具
大部分人都知道redis是一款用在缓存服务器上的软件,它与memcache类似,都可以存储海量的数据,用在大访问量的web网站.聊天记录存放等方面,但是又与memcache不同: 1.缓存数据可以持久 ...
- HDU2181 哈密顿绕行世界问题 —— DFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2181 哈密顿绕行世界问题 Time Limit: 3000/1000 MS (Java/Others) ...
- YTU 2209: 建立链表(线性表)
2209: 建立链表(线性表) 时间限制: 1 Sec 内存限制: 128 MB 提交: 282 解决: 185 题目描述 (线性表)设键盘输入n个英语单词,输入格式为n, w1, w2, -,w ...
- CoreData兼容iOS9和iOS10
由于iOS10之后CoreData Stack的更改无法在iOS9的系统中运行,所以我们需要对上一小节中封装的工具类进行系统版本的兼容 iOS9和iOS10中CoreData最本质的区别其实就是管理对 ...
- 添加.pch文件
完成框架, .pch文件 1.创建.pch文件 2.配置.pch文件 双击,改成:项目名/pch文件名