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. 在VS2013下配置BOOST库

    1.安装Boost库 (1).首先打开Boost的官网(http://www.boost.org/),找到下载位置,如下图中红框所示,此时最新的版本是1.64.0: (2).点击进入下载页面,选择你需 ...

  2. Halcon一日一练:图像设备介绍

    Halcon在设计之初就提供了完整的图像采集方案,适应了多种图像设备采集图像,以及各种不同环境的采集方案. 通常情况下,图像的采集应该是所有机器视觉项目首要解决的任务,不幸的是,需要解决图像采集的问题 ...

  3. opencv::基本阈值操作

    图像阈值(threshold) 阈值 是什么?简单点说是把图像分割的标尺,这个标尺是根据什么产生的,阈值产生算法?阈值类型.(Binary segmentation) 阈值类型一阈值二值化(thres ...

  4. MFC::使用mysql

    下载mysql-installer-community-5.7.16.0.msi,安装 mysql server即可. 创建工程包含头文件 #include "winsock.h" ...

  5. 关于a标签的href属性

    今天有人问起我a标签的href属性值为 # 与 JavaScript:void(0) 有啥区别,想来也没啥可说,就简单说两句 a标签的href属性,优点有: 天然鼠标手型,以及可以被键盘focus以及 ...

  6. Newman基本使用

    简介 Newman 是 Postman 推出的一个 nodejs 库,直接来说就是 Postman 的json文件可以在命令行执行的插件. Newman 可以方便地运行和测试集合,并用之构造接口自动化 ...

  7. js静态属性,实例属性,封装性,prototype,__proto__综合解析

    原创作品,转载请注明来源,sogeisetsu,我的csdn上也有这篇文章csdn js静态属性,实例属性,封装性,prototype,__proto__综合解析 下面是我在写博客的源代码,您可以先不 ...

  8. CasperJS 前端功能测试

    CasperJS 是一个开源的导航脚本和测试组件.它提供实用的高级函数.方法和语法糖,可完成以下任务: 对浏览导航步骤的定义和排序 填写和提交表单 点击和跟踪链接 获取页面快照(或者页面中的某部分) ...

  9. pytest -- 中文文档

    pytest-chinese-doc pytest官方文档(5.1.3版本)的中文翻译,但不仅仅是简单的翻译: 更多的例子,尽量做到每一知识点都有例子: 更多的拓展阅读,部分章节添加了作者学习时,所查 ...

  10. 框架搭建与EF常用基类实现

    前两篇简单谈了一些.Net Core的优势以及机构设计的一些思路,这一篇开始,我们将从零开始搭建架构,底层我们将采用EF来访问数据库,所以这篇我们将贴一下EF常用操作的基类. 简单介绍下一些类库将要实 ...