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 ...
随机推荐
- [HDOJ3308]LCIS(线段树,区间合并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 题意:给定n个数,两个操作: U A B:将位置A的数值改成B Q A B:查询[A,B]内最长 ...
- sql server日期时间函数
From:http://www.cnblogs.com/linzheng/archive/2010/11/17/1880208.html 1. 当前系统日期.时间 select getdate() ...
- 【原】使用SQLite打开本地*.db文件
1.下载安装文件:官网下载地址:http://www.sqlite.org/download.html32位安装包:http://www.sqlite.org/2016/sqlite-tools-wi ...
- 关于gitlab的一个问题解决
这两天折腾一个关于gitlab的问题,搞得比较焦头烂额.不过经过折腾,最终还是成功了. 当面对着一个问题,并且看到还没被解决的时候,感觉很不舒服: 努力折腾之后,解决之后,也会身体轻松.或许工程师天生 ...
- Android中的五大布局和logcat打印日志
在android中的布局有五大类,有的时候你可能用到一种,但有的时候你也可能需要两种或者三种布局同时一起使用.这五种布局为别为:LinearLayout(线性布局),FrameLayout(框架布局) ...
- Android 使用finalBitmap实现缓存读取
public class NewsApplication extends Application{ private FinalBitmap finalBitmap=null; public Final ...
- Nginx 的RTMP打流模块配置
config配置文件: user www www; worker_processes ; error_log logs/error.log debug; #pid logs/nginx.pid; ev ...
- oracle 查看锁表情况并处理锁表
/* *locked *query locked object and analyse reason,kill it * */ select 'alter system kill session '' ...
- JS获取URL中参数值(QueryString)的4种方法分享<转>
方法一:正则法 复制代码代码如下: function getQueryString(name) { var reg = new RegExp('(^|&)' + name + '=([^ ...
- spring校验和文件上传
spring校验可以分为 vlidator和jsr303 vlidator实例 首先实现validatorjiekou 通过这个类转化为验证类,然后进行验证 在handler里通过创建进行验证 通过j ...