hdu 1162 Eddy's picture (prim)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11970 Accepted Submission(s): 6008
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?
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.
Your program prints a single real number to two decimal places: the minimum total length of ink lines that can connect all the points.
3
1.0 1.0
2.0 2.0
2.0 4.0
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)的更多相关文章
- 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 (Kruskal 算法)
题目连接: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
坐标之间的距离的方法,prim算法模板. Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32 ...
- 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 (最小生成树 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
Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to become ...
- hdu 1162 Eddy's picture(最小生成树,基础)
题目 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<string.h> #include <ma ...
随机推荐
- python学习-异常处理之捕获异常与抛出异常(七)
捕获异常 python完整的异常处理语法结构如下: 特别说明: 1.try块是必需的,except块和finally,当try块没有出现异常时,程序会执行else块 2.try块后只有一个except ...
- python-从文件中读取数据
一.读取整个文件 learnFile.py 绝对路径 # coding=UTF-8 import sys reload(sys) with open(r'C:\Users\zhujiachun\Des ...
- 详细解读 Spring AOP 面向切面编程(二)
本文是<详细解读 Spring AOP 面向切面编程(一)>的续集. 在上篇中,我们从写死代码,到使用代理:从编程式 Spring AOP 到声明式 Spring AOP.一切都朝着简单实 ...
- 设计模式(十五)Facade模式
Facade模式可以为相互关联在一起的错综复杂的类整理出高层接口,可以让系统对外只有一个简单的接口,而且还会考虑到系统内部各个类之间的责任关系和依赖关系,按照正常的顺序调用各个类. 还是先看一下示例程 ...
- Django的下载与基本命令
1.下载Django: pip3 install django==2.1.2 2.创建一个django project django-admin startproject 项目名称 3.在项目目录下创 ...
- github 下载子目录内容 亲测可用!
下载我的LYBTouchID项目的Kit目录内容 (1)在github上点开这个目录,浏览器地址栏可以得到这个地址 https://github.com/Liuyubao/LYBTouchID/tre ...
- Java开发中的23中设计模式详解(一)工厂方法模式和抽象工厂模式
一.设计模式的分类 总体来说设计模式分为三大类: 创建型模式,共五种:工厂方法模式.抽象工厂模式.单例模式.建造者模式.原型模式. 结构型模式,共七种:适配器模式.装饰器模式.代理模式.外观模式.桥接 ...
- 使用koa-mysql-session时报错
描述 在本地测试代码没问题,但是部署到服务器上时就报错. 错误 > cross-env WEBPACK_TARGET=node NODE_ENV=production node ./server ...
- Netty 入门,这一篇文章就够了
Netty是Java领域有名的开源网络库,特点是高性能和高扩展性,因此很多流行的框架都是基于它来构建的,比如我们熟知的Dubbo.Rocketmq.Hadoop等,针对高性能RPC,一般都是基于Net ...
- SpringCloud 中集成Sentinel+Feign实现服务熔断降级
Sentine 1.背景 Sentinel 是阿里中间件团队开源的,面向分布式服务架构的轻量级高可用流量控制组件,主要以流量为切入点,从流量控制.熔断降级.系统负载保护等多个维度来帮助用户保护服务的稳 ...