坐标之间的距离的方法,prim算法模板。

Eddy's picture

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5620    Accepted Submission(s): 2821

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
Author
  1. #include<stdio.h>
  2. #include<math.h>
  3. #define N 110
  4. #define max 9999999
  5. double map[N][N];
  6. void prim(int n)
  7. {
  8. int i,j,u,flag,mark[N];
  9. double dis[N],cost,min;
  10. for(i=;i<n;i++)
  11. {
  12. mark[i]=;
  13. dis[i]=map[][i];
  14. }
  15. mark[]=;
  16. cost=;
  17. for(i=;i<n;i++)
  18. {
  19. min=max;
  20. for(j=;j<n;j++)
  21. if(!mark[j]&&min>dis[j])
  22. {
  23. u=j;
  24. min=dis[j];
  25. }
  26.  
  27. mark[u]=;
  28. cost+=min;
  29. for(j=;j<n;j++)
  30. if(!mark[j]&&dis[j]>map[u][j])
  31. dis[j]=map[u][j];
  32. }
  33. printf("%.2f\n",cost);
  34. }
  35. int main()
  36. {
  37. int i,j,n;
  38. double dis,x2,y2,x[N],y[N];
  39. while(~scanf("%d",&n))
  40. {
  41. for(i=;i<n;i++)
  42. scanf("%lf%lf",&x[i],&y[i]);
  43. for(i=;i<n;i++)
  44. for(j=;j<=i;j++)
  45. {
  46. x2=(x[i]-x[j])*(x[i]-x[j]);
  47. y2=(y[i]-y[j])*(y[i]-y[j]);
  48. dis=sqrt(x2+y2);
  49. if(i==j)
  50. map[j][i]=map[i][j]=;
  51. else
  52. map[i][j]=map[j][i]=dis;
  53. }
  54. prim(n);
  55. }
  56. return ;
  57. }

HDU 1162 Eddy's picture的更多相关文章

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

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

    题目链接: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 (最小生成树)

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

  5. hdu 1162 Eddy's picture (prim)

    Eddy's pictureTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  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. linux 搭建pptpd vpn(转,备忘)

    1.第一步需要安装PPTP,以用来提供VPN服务.sudo apt-get install pptpd注:如果有问题的话比如提示找不到之类的,apt-get update 一下应该就可以了,然后再来一 ...

  2. ubuntu vim之php函数提示

    参考文献:http://www.feiyan.info/32.html 折腾半天 原来是phpfunclist.txt不正确...... vim的配置在~/.vimrc (既你的home主目录 ,例如 ...

  3. 【原创】Linux编译内核

    Linux 编译内核 大致分这几个步骤 1.准备编译工具.内核文件 2.开始编译 3.将编译好的新内核install进系统 4.查看是否成功.   一.准备好必备的库和内核文件   1.添加必备的编译 ...

  4. 【笔记-前端】div+css排版基础,以及错误记录

    现在的网站对于前端的排版已经逐渐不使用<table>,而是使用div+css. 使用这种方法的最大好处就在于在维护页面时,可以只维护css而不去改动html. 可是这种方式对于初学者来说可 ...

  5. JS将时间戳转换为JS Date类型

    /*将JSON Date 格式转换为JavaScript 的Date 类型JSON Date 格式:"/Date(146471041000)/"*/function JSONDat ...

  6. wpf采用Xps实现文档显示、套打功能(原创)

    近期的一个项目需对数据进行套打,用户要求现场不允许安装office.页面预览显示必须要与文档完全一致,xps文档来对数据进行处理.Wpf的DocumentView 控件可以直接将数据进行显示,xps也 ...

  7. 禁止选择文本和禁用右键 v2.0

    禁止鼠标右键(注:在火狐浏览器没有起到效果作用) <script> function stop() { return false }; document.oncontextmenu = s ...

  8. MySQL数据库添加一个字段

    MySQL数据库添加一个字段 1.添加一个字段 alter table tableName add 列名  数据类型; 2.添加一个字段设置默认值 alter table tableName add ...

  9. Linux - tar命令过滤某个目录

    tar -zcvf abc.20140325.tar.gz --exclude=./abc/kkk/--exclude=./abc/hhh/ ./abc/ 发现没有过滤成功,后来发现这种方法是不对的( ...

  10. Android Context创建过程

        特定的资源或者类构成了Android应用程序的运行上下文环境 PackageManager, ClassLoader, Assert等等 Android应用程序窗口的运行上下文环境是通过Con ...