(最小生成树)Eddy's picture -- hdu -- 1162
链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1162
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8303 Accepted Submission(s): 4214
Problem descriptions as follows: Given you some coordinates pionts on a drawing paper, every point links with the ink with the straight line, causes all points finally to link in the same place. How many distants does your duty discover the shortest length which the ink draws?
Input contains multiple test cases. Process to the end of file.
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <queue>
#include <algorithm>
using namespace std; const int oo = 0x3f3f3f3f;
const int N = ; struct node
{
double x, y;
}s[N]; int n, vis[N];
double dist[N], G[N][N]; double prim()
{
double ans = ;
for(int i=; i<=n; i++)
dist[i] = G[][i]; memset(vis, , sizeof(vis));
vis[] = ; for(int i=; i<=n; i++)
{
int index=;
double Min=oo;
for(int j=; j<=n; j++)
{
if(!vis[j] && dist[j]<Min)
{
Min = dist[j];
index = j;
}
} if(index==)
continue; vis[index] = ;
ans += Min; for(int j=; j<=n; j++)
{
if(!vis[j] && dist[j] > G[index][j])
{
dist[j] = G[index][j];
}
}
}
return ans;
} int main()
{
while(scanf("%d", &n)!=EOF)
{
for(int i=; i<=n; i++)
scanf("%lf%lf", &s[i].x, &s[i].y); for(int i=; i<=n; i++)
for(int j=; j<=i; j++)
G[i][j] = G[j][i] = sqrt((s[i].x-s[j].x)*(s[i].x-s[j].x)+(s[i].y-s[j].y)*(s[i].y-s[j].y) ); printf("%.2f\n", prim());
}
return ;
}
(最小生成树)Eddy's picture -- hdu -- 1162的更多相关文章
- hdoj 1162 Eddy's picture
并查集+最小生成树 Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- 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(最小生成树算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...
- 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 (Kruskal 算法)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...
- HDU 1162 Eddy's picture
坐标之间的距离的方法,prim算法模板. Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32 ...
- hdu Eddy's picture (最小生成树)
Eddy's picture Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tota ...
- hdu 1162 Eddy's picture (prim)
Eddy's pictureTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu 1162(最小生成树)
Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
随机推荐
- C语言课程设计——电影院订票系统
1. 课题简介 大家都爱看电影,现请参考一个熟悉电影票预订系统,实现C语言版的订票系统.了解订票如何实现的.系统主要有2类用户:管理员用户和顾客用户. 管理员用户登录系统后,实现电影放映厅信息管理和电 ...
- Android XML数据解析
XML:可扩展标记语言.一般用于数据存储,SharedPreference就是使用xml文件保存信息的,SQLite底层也是xml文件,在网络方面通常作为信息的载体,把数据包装成xml来传递. XML ...
- Spark系列(二) Spark Shell各种操作及详细说明
并行化scala集合(Parallelize) //加载数据1~10 val num=sc.parallelize(1 to 10) //每个数据项乘以2,注意 _*2记为一个函数(fun) val ...
- postman-3断言
用例3A原则: arrange:初始化测试对象 act:操作.接口测试中通过不同的参数调用接口. assert:断言 snippets提供了一些断言的使用方法. 在新版的postman中,test中方 ...
- mysql-12序列使用
mysql序列是一组整数:1,2,3....,由于一张数据表只能有一个字段自增主键,如果你想实现其他字段自动增加,就可以使用mysql序列来实现. 使用auto_increment来定义列 drop ...
- ubuntu 下出现E: Sub-process /usr/bin/dpkg returned an error code
在用apt-get安装软件时出现了类似于 install-info: No dir file specified; try –help for more information.dpkg:处理 get ...
- 符合RESTful规范的API
统一使用的utils,serializers: class BaseResponse: def __init__(self): self.code = 1000 self.data = None se ...
- [jOOQ中文]2. jOOQ与Spring和Druid整合
https://segmentfault.com/a/1190000010496053 jOOQ和Spring很容易整合. 在这个例子中,我们将整合: Alibaba Druid(但您也可以使用其他连 ...
- 第4章 类与对象 UML简介
- Python3 hex() 函数
Python3 hex() 函数 Python3 内置函数 描述 hex() 函数用于将一个指定数字转换为 16 进制数. 语法 hex 语法: hex(x) 参数说明: x -- 一个整数 返回值 ...