链接:

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 Description
Eddy begins to like painting pictures recently ,he is sure of himself to become a painter.Every day Eddy draws pictures in his small room, and he usually puts out his newest pictures to let his friends appreciate. but the result it can be imagined, the friends are not interested in his picture.Eddy feels very puzzled,in order to change all friends 's view to his technical of painting pictures ,so Eddy creates a problem for the his friends of you.
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
The first line contains 0 < n <= 100, the number of point. For each point, a line follows; each following line contains two real numbers indicating the (x,y) coordinates of the point.

Input contains multiple test cases. Process to the end of file.

 
Output
Your program prints a single real number to two decimal places: the minimum total length of ink lines that can connect all the points. 
 
Sample Input
3
1.0 1.0
2.0 2.0
2.0 4.0
 
Sample Output
3.41

代码:

#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的更多相关文章

  1. hdoj 1162 Eddy's picture

    并查集+最小生成树 Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  2. HDU 1162 Eddy's picture (最小生成树)(java版)

    Eddy's picture 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 ——每天在线,欢迎留言谈论. 题目大意: 给你N个点,求把这N个点 ...

  3. hdu 1162 Eddy's picture(最小生成树算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...

  4. hdu 1162 Eddy's picture (最小生成树)

    Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  5. 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 ...

  6. HDU 1162 Eddy's picture

    坐标之间的距离的方法,prim算法模板. Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32 ...

  7. hdu Eddy's picture (最小生成树)

    Eddy's picture Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tota ...

  8. hdu 1162 Eddy's picture (prim)

    Eddy's pictureTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  9. hdu 1162(最小生成树)

    Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

随机推荐

  1. Mac 下使用brew install 报错: Cowardly refusing to `sudo brew install'

    Mac 下使用brew install 报错: localhost:infer-osx-v0.6.0 admin$ sudo brew install opam Error: Cowardly ref ...

  2. WinForm 每用户只允许创建一个实例

    string mutexName = System.Environment.UserName + "nono"; bool runone; System.Threading.Mut ...

  3. OpenSSL生成root CA及签发证书

    一.openssl 简介 openssl 是目前最流行的 SSL 密码库工具,其提供了一个通用.健壮.功能完备的工具套件,用以支持SSL/TLS 协议的实现.官网:https://www.openss ...

  4. php 面试一般都遇到什么问题

    大型互联网公司会从几个方面来考核:第一:专业上,专业分为五个方向,操作系统,网络,算法,语言,数据库,一般情况下,会比较在乎Linux系统的日常使用,包括shell脚本,比较深入的话,会问kernel ...

  5. Java 学习思路

    内容中包含 base64string 图片造成字符过多,拒绝显示

  6. c语言个人财务管理系统

    这个是我的一个网上朋友写的,仅供大家参考: 在这里留个记录 #include<stdio.h>#include<string.h>#define null 0#define m ...

  7. Linux-vim编辑器与shell的简介

    VIM编辑器  vi是Visual interface的简称,它可以执行输出.删除.查找.替换.块操作等众多文本操作. 用户可以根据自己的需要对vim进行定制,这是其他编辑程序所没有的. vim不是一 ...

  8. libcurl使用心得-包括下载文件不存在处理相关(转)

    libcurl使用心得 Libcurl为一个免费开源的,客户端url传输库,支持FTP,FTPS,TFTP,HTTP,HTTPS,GOPHER,TELNET,DICT,FILE和LDAP,跨平台,支持 ...

  9. UNITY插件信息收集

    2018.8.7 UNITY超级优化神器 : Amplify Impostors

  10. Linux学习-linux系统下python升级到python3.6步骤详解,以及遇到的问题解决

    说明:一般linux会自带pyhton2.7 1.首先下载源tar包 可利用linux自带下载工具wget下载,如下所示: wget http://www.python.org/ftp/python/ ...