HDUOJ-----(1162)Eddy's picture(最小生成树)
Eddy's picture
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6821 Accepted Submission(s): 3444
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.
1.0 1.0
2.0 2.0
2.0 4.0
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=;
double map[maxn][maxn];
double lowc[maxn];
bool vis[maxn];
struct point{ double x,y;
int id;
}; inline double dista(point a,point b){
return sqrt((a.y-b.y)*(a.y-b.y)+(a.x-b.x)*(a.x-b.x));
} point sac[maxn]; double prim(int st,int n)
{
memset(vis,,sizeof(vis));
vis[st]=true;
double minc=inf;
for(int i=;i<=n;i++)
lowc[i]=map[st][i];
int pre=st;
double sum=0.0;
for(int i=;i<n;i++){
minc=inf;
for(int j=;j<=n;j++)
{
if(!vis[j]&&minc>lowc[j]){
minc=lowc[j];
pre=j;
}
}
sum+=minc;
vis[pre]=true;
for(int j=;j<=n;j++){
if(!vis[j]&&lowc[j]>map[pre][j]){
lowc[j]=map[pre][j];
}
}
}
return sum;
}
void work(int n)
{
for(int i=;i<n;i++){
for(int j=;j<n;j++){
map[i+][j+]=map[j+][i+]=dista(sac[i],sac[j]);
}
}
}
int main(){
int n;
while(scanf("%d",&n)!=EOF){ for(int i=;i<n;i++)
{
scanf("%lf%lf",&sac[i].x,&sac[i].y);
sac[i].id=i+;
}
work(n);
printf("%.2lf\n",prim(,n));
}
return ;
}
HDUOJ-----(1162)Eddy's picture(最小生成树)的更多相关文章
- 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 (最小生成树)(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 (Kruskal 算法)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...
- 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
坐标之间的距离的方法,prim算法模板. Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32 ...
- 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 (最小生成树 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(最小生成树,基础)
题目 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<string.h> #include <ma ...
随机推荐
- HQL语句大全(转载)
Hibernate配备了一种非常强大的查询语言,这种语言看上去很像SQL.但是不要被语法结构 上的相似所迷惑,HQL是非常有意识的被设计为完全面向对象的查询,它可以理解如继承.多态 和关联之类的概念. ...
- MyBatis 动态SQL查询,多条件,分页
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-/ ...
- JDBC操作Oracle数据库——实际操作过程中的小总结
1.对数据库中,表的每一行数据记录的增删改查 增:insert into 表名 values() 删:delete 表名 where 条件(id=?) 改:update 表名 set 列名=? whe ...
- C++ Redis mset 二进制数据接口封装方案
C++ Redis mset 二进制数据接口封装方案 需求 C++中使用hiredis客户端接口访问redis: 需要使用mset一次设置多个二进制数据 以下给出三种封装实现方案: 简单拼接方案 在r ...
- python_way day14 CSS
python_way day14 CSS 层叠样式表 一.CSS作用域: 二.css标签选择器 三.css样式 一.css作用域: 基本用法:style="样式" <body ...
- style不同取值对应的日期、时间格式
from : http://www.cnblogs.com/Gavinzhao/archive/2009/11/10/1599690.html sql server2000中使用convert来取得d ...
- 07 SQL优化技术
本章提要------------------------------------------------------调优技术及什么时候使用------------------------------- ...
- Linux下搭建SVN服务
SVN有几种方式进行访问,比较常见的是通过自带协议访问(svn://),配置很简单,还有一种就是http协议访问,需要结合apache服务,配置相对繁琐. 安装svn yum -y install s ...
- JVM系列三:JVM参数设置、分析
不管是YGC还是Full GC,GC过程中都会对导致程序运行中中断,正确的选择不同的GC策略,调整JVM.GC的参数,可以极大的减少由于GC工作,而导致的程序运行中断方面的问题,进而适当的提高Java ...
- mybatis实战
这篇教程不错,推荐:http://blog.csdn.net/techbirds_bao/article/details/9233599/