坐标之间的距离的方法,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. window redis 安装配置

    1 下载 https://github.com/MSOpenTech/redis/releases 当前最新版本为 redis-2.8.21   下载的为zip包,下载连接为:https://gith ...

  2. CSS边框属性二---border-images

    border-images 属性 主要用border-images 属性来制作自适应按钮和tab标签&自适应边框. 例子: border-images:url("img.png&qu ...

  3. [转] jQuery按键响应事件keypress对应的按键编码keycode

    原文地址:http://blog.csdn.net/chenhj1988918/article/details/7534922 keypress  api 文档:http://api.jquery.c ...

  4. (hdu)5546 Ancient Go

    Problem Description Yu Zhou likes to play Go with Su Lu. From the historical research, we found that ...

  5. nginx 显示discuz页面

    我也不知道我题目表述的对不对.我也是刚学习. 安装nginx 显示discuz的界面.我看了好几次视频,也没发现哪的问题.就是一直出现502的错误代码 我又重新查了几次.觉得需要注意一下几点: 1,关 ...

  6. 开发错误日志之Unix/Linux命令未执行或无结果等且程序无错误

    在Unix/Linux环境中开发时,特别要注意权限问题,否则经常找不到错误的原因,其实就是因为权限所致.

  7. Linux文件权限学习总结

    一.用户对文件或目录都有哪些权限? 四种:读.写.执行.没有权限 二.如何表示这四种权限? 如果用十进制数字表示,分别为:4.2.1.0:如果用字符表示,分别为:r.w.x.-.个人觉得,使用chmo ...

  8. MySQL数据库原理

    我们知道,数据是信息的载体——一种我们约定了如何解释的符号.在计算机系统中,最常见的应该是文本数据.我们用它记录配置信息,写日志,等等.而在应用程序中,按一定的数据结构来组织数据的方式叫做数据库管理系 ...

  9. SVG绘制圆形简单示例分享

    今天分享“svg绘制圆形”部分 1.简单圆形 效果图如下: 关键代码: <svg xmlns="http://www.w3.org/2000/svg" version=&qu ...

  10. js在本地预览图片

    移动web <body> <form enctype="multipart/form-data" name="form1"> 上传文件: ...