Eddy's picture
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11970    Accepted Submission(s): 6008
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

C/C++:

 #include <cmath>
#include <cstdio>
#include <climits>
#include <algorithm>
using namespace std; int n;
double my_map[][]; struct node
{
double a, b;
}P[]; double my_prim()
{
int my_pos = , my_book[] = {, };
double my_ans = 0.0, my_dis[] = {, INT_MAX};
for (int i = ; i <= n; ++ i)
my_dis[i] = my_map[i][my_pos]; for (int i = ; i < n; ++ i)
{
double my_temp = INT_MAX;
for (int j = ; j <= n; ++ j)
{
if (!my_book[j] && my_dis[j] < my_temp)
{
my_temp = my_dis[j];
my_pos = j;
}
}
my_ans += my_temp;
my_book[my_pos] = ;
for (int j = ; j <= n; ++ j)
{
if (!my_book[j] && my_dis[j] > my_map[j][my_pos])
my_dis[j] = my_map[j][my_pos];
}
}
return my_ans;
} int main()
{
/**
Date Input Initialize
*/
while (~scanf("%d", &n))
{
for (int i = ; i <= n; ++ i)
scanf("%lf%lf", &P[i].a, &P[i].b);
for (int i = ; i <= n; ++ i)
{
for (int j = i+; j <= n; ++ j)
{
double my_temp_a = (P[i].a - P[j].a) * (P[i].a - P[j].a);
double my_temp_b = (P[i].b - P[j].b) * (P[i].b - P[j].b);
double my_temp = sqrt(my_temp_a + my_temp_b);
my_map[i][j] = my_map[j][i] = my_temp;
}
}
printf("%.2lf\n", my_prim());
}
return ;
}

hdu 1162 Eddy's picture (prim)的更多相关文章

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

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

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

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

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

  4. HDU 1162 Eddy's picture

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

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

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

  6. HDU 1162 Eddy's picture (最小生成树 prim)

    题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...

  7. HDU 1162 Eddy's picture (最小生成树 普里姆 )

    题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...

  8. 题解报告:hdu 1162 Eddy's picture

    Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to become ...

  9. hdu 1162 Eddy's picture(最小生成树,基础)

    题目 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<string.h> #include <ma ...

随机推荐

  1. Ubuntu使用中遇到的的一些问题

    制作ubuntu启动盘后,U盘只读. ubuntu自带的"启动盘创建器(usb-creator-gtk)"制作启动盘后,U盘只读. 打开ubuntu自带的"磁盘(hard ...

  2. MariaDB数据库

      MySQL作者Michael Widenius自己创办了新公司Monty Program AB,在MySQL基础上新创了MariaDB开源数据库.MariaDB带来更好的数据库管理特性,更好的自由 ...

  3. 概念理解-Libevent

    可移植性: 使用 LibEvent 编写的程序应该在 LibEvent 支持跨越的所有平台上工作,即使没有更好的方法来处理. 非阻塞式IO:LibEvent也应该支持一般的方法使程序可以运行在某些限制 ...

  4. c++::Mysql::ORM 开发环境搭建

    官网地址:https://www.codesynthesis.com/products/odb/ 环境搭建:ubuntu16.04-64 1.安装mysqlClient sudo apt-get in ...

  5. Git & Github 使用教程【1】入门篇

    Github教程 1-1 版本管理工具简介 主要作用:备份文件.记录历史.回到过去.多端共享.独挡一面.团队协作 2-1 版本管理工具发展历史 3-1 Git下载和安装[略] 3-2 linux下安装 ...

  6. StringBuffer类讲解

    package Main; import java.util.Scanner; public class Main { public static void main(String[] args) { ...

  7. Spring Boot从零入门1_详述

    本文属于原创,转载注明出处,欢迎关注微信小程序`小白AI博客` 微信公众号`小白AI`或者网站 [https://xiaobaiai.net](https://xiaobaiai.net) ![](h ...

  8. .net core跨平台应用研究-ubuntu core下配置.net core运行时

    引言 年初研究了一阵子.net core跨平台应用,先后发表了几篇应用研究的文章.因工作原因,忙于项目上线,有一阵子没来博客园写文章了.最近项目基本收尾,抽空翻了下自己的博客,廖廖几篇文章,真让人汗颜 ...

  9. C语言 二叉树的遍历(递归和非递归)

    #include <iostream> #include <cstdio> #include "biTree.h" #include "cstdl ...

  10. codeblocks 调试不停止的解决办法。

    CB的工程路径不能有中文,也不能有空格. 所以一定要全英文路径,而且空格要用下划线代替. 否则,调试的时候,codeblocks不会在断点处停止.