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. [Luogu2359] 三素数数

    题目背景 蛟川书院的一道练习题QAQ 题目描述 如果一个数的所有连续三位数字都是大于100的素数,则该数称为三素数数.比如113797是一个6位的三素数数. 输入输出格式 输入格式: 一个整数n(3 ...

  2. nginx::环境搭建

    ubuntu18.04 环境 1.需要gcc 环境,如果没有gcc环境,则需要安装 apt install gcc .安装pcre依赖库 PCRE(Perl Compatible Regular Ex ...

  3. 【OUC2019写作】论文写作第九小组英语常用表达整理

    第一部分:  一.简要综述以往和现在研究: 某方法被认为如何如何:it is well known that; it is regarded as; it is believed to ; It is ...

  4. asp.net core mvc中自定义ActionResult

    在GitHub上有个项目,本来是作为自己研究学习.net core的Demo,没想到很多同学在看,还给了很多星,所以觉得应该升成3.0,整理一下,写成博分享给学习.net core的同学们. 项目名称 ...

  5. Go.js 没有中文文档 也没有中文demo 学起来很费劲 给大家整理一个算是详细的文档

    <!DOCTYPE html> <html> <head> <meta name="viewport" content="wid ...

  6. ESP8266开发之旅 网络篇⑨ HttpClient——ESP8266HTTPClient库的使用

    授人以鱼不如授人以渔,目的不是为了教会你具体项目开发,而是学会学习的能力.希望大家分享给你周边需要的朋友或者同学,说不定大神成长之路有博哥的奠基石... QQ技术互动交流群:ESP8266&3 ...

  7. Markdown进阶(1)

    对于工科生来说,在书写Markdown文本时,免不了要和上下标打交道,网上的博客大多良莠不齐,不太友好,本文想尽可能地解决一些在看完基础教程后再来书写Markdown文本时容易遇到的问题. 1.上下标 ...

  8. LeetCode 十月份题目汇总

    开源地址:点击该链接 前言 十月份共有60道题目,全部属于 Easy 难度的,所以公众号中分享出来的并不多,只是挑了一些感觉还可以的才分享了出来,这60道题目我按照不同类别进行了分类整理,所有源码以及 ...

  9. Spring Cloud Feign初接触

    最近想使用下Feign,然后简单了解了一下,简单的搭了个demo. 首先简单介绍一下Feign,它是一个Http请求客户端,类似HttpClient,具体里面实现还没去看,知道它是一个请求客户端就行, ...

  10. Java多线程编程(三)线程间通信

    线程是操作系统中独立的个体,但这些个体如果不经过特殊的处理就不能成为一个整体.线程间的通信就是成为整体的必用方案之一,可以说,使线程间进行通信后,系统之间的交互性会更强大,在大大提高CPU利用率的同时 ...