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++:

  1. #include <cmath>
  2. #include <cstdio>
  3. #include <climits>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. int n;
  8. double my_map[][];
  9.  
  10. struct node
  11. {
  12. double a, b;
  13. }P[];
  14.  
  15. double my_prim()
  16. {
  17. int my_pos = , my_book[] = {, };
  18. double my_ans = 0.0, my_dis[] = {, INT_MAX};
  19. for (int i = ; i <= n; ++ i)
  20. my_dis[i] = my_map[i][my_pos];
  21.  
  22. for (int i = ; i < n; ++ i)
  23. {
  24. double my_temp = INT_MAX;
  25. for (int j = ; j <= n; ++ j)
  26. {
  27. if (!my_book[j] && my_dis[j] < my_temp)
  28. {
  29. my_temp = my_dis[j];
  30. my_pos = j;
  31. }
  32. }
  33. my_ans += my_temp;
  34. my_book[my_pos] = ;
  35. for (int j = ; j <= n; ++ j)
  36. {
  37. if (!my_book[j] && my_dis[j] > my_map[j][my_pos])
  38. my_dis[j] = my_map[j][my_pos];
  39. }
  40. }
  41. return my_ans;
  42. }
  43.  
  44. int main()
  45. {
  46. /**
  47. Date Input Initialize
  48. */
  49. while (~scanf("%d", &n))
  50. {
  51. for (int i = ; i <= n; ++ i)
  52. scanf("%lf%lf", &P[i].a, &P[i].b);
  53. for (int i = ; i <= n; ++ i)
  54. {
  55. for (int j = i+; j <= n; ++ j)
  56. {
  57. double my_temp_a = (P[i].a - P[j].a) * (P[i].a - P[j].a);
  58. double my_temp_b = (P[i].b - P[j].b) * (P[i].b - P[j].b);
  59. double my_temp = sqrt(my_temp_a + my_temp_b);
  60. my_map[i][j] = my_map[j][i] = my_temp;
  61. }
  62. }
  63. printf("%.2lf\n", my_prim());
  64. }
  65. return ;
  66. }

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. PHP array_change_key_case

    (PHP 4 >= 4.2.0, PHP 5, PHP 7) 1.函数的作用 : 改变数组所有键值的大小写: 2.参数: 1)array : 应用的数组: 2)case  : 指定转换为大写或者 ...

  2. The All-in-One Note

    基础 操作系统 I/O 模型 阻塞式 I/O 模型(blocking I/O) 描述:在阻塞式 I/O 模型中,应用程序在从调用 recvfrom 开始到它返回有数据报准备好这段时间是阻塞的,recv ...

  3. ESP8266开发之旅 进阶篇② 闲聊Arduino IDE For ESP8266烧录配置

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

  4. 解决Zend OPcache huge_code_pages: mmap(HUGETLB) failed: Cannot allocate memory报错

    前几日看到鸟哥介绍的 <让你的PHP7更快之Hugepage>, 于是想试试手给服务器加上,参照格式安装好扩展,调整好配置文件,然后重启php-fpm,结果启动一直报Zend OPcach ...

  5. Mybaits 源码解析 (四)----- SqlSession的创建过程(看懂框架源码再也不用死记硬背面试题)

    SqlSession是mybatis的核心接口之一,是myabtis接口层的主要组成部分,对外提供了mybatis常用的api.myabtis提供了两个SqlSesion接口的实现,常用的实现类是De ...

  6. javascript实用代码片段

    持续积累中~ 拓展原型 Function.prototype.method = function(name, extend) { if(!this.prototype[name]) { this.pr ...

  7. EFCore--->> CodeFirst (Vs2019 Core3.0)的简单使用

    直接上干货 EFCore--->> CodeFirst (Vs2019 Core3.0) 1: 安装下面3个对应的package(在Nuget控制台或者直接NuGet包查询点击下载,我喜欢 ...

  8. Java基础(二十一)集合(3)List集合

    一.List接口 List集合为列表类型,列表的主要特征是以线性方式存储对象. 1.实例化List集合 List接口的常用实现类有ArrayList和LinkedList,根据实际需要可以使用两种方式 ...

  9. Unity事件系统

    # 1.前言Unity中事件/委托有着广泛的应用,本文通过封装一个简易的事件的系统,来统一管理消息的传递.此功能在简易应用或者事件较少的体现不出太好的作用,但是对于事件应用较多时,可以减少脚本之间的耦 ...

  10. python之ORM(对象关系映射)

    实现了数据模型与数据库的解耦,通过简单的配置就可以轻松更换数据库,而不需要更改代码.orm操作本质上会根据对接的数据库引擎,翻译成对应的sql语句.所有使用Django开发的项目无需关心程序底层使用的 ...