坐标之间的距离的方法,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
#include<stdio.h>
#include<math.h>
#define N 110
#define max 9999999
double map[N][N];
void prim(int n)
{
int i,j,u,flag,mark[N];
double dis[N],cost,min;
for(i=;i<n;i++)
{
mark[i]=;
dis[i]=map[][i];
}
mark[]=;
cost=;
for(i=;i<n;i++)
{
min=max;
for(j=;j<n;j++)
if(!mark[j]&&min>dis[j])
{
u=j;
min=dis[j];
} mark[u]=;
cost+=min;
for(j=;j<n;j++)
if(!mark[j]&&dis[j]>map[u][j])
dis[j]=map[u][j];
}
printf("%.2f\n",cost);
}
int main()
{
int i,j,n;
double dis,x2,y2,x[N],y[N];
while(~scanf("%d",&n))
{
for(i=;i<n;i++)
scanf("%lf%lf",&x[i],&y[i]);
for(i=;i<n;i++)
for(j=;j<=i;j++)
{
x2=(x[i]-x[j])*(x[i]-x[j]);
y2=(y[i]-y[j])*(y[i]-y[j]);
dis=sqrt(x2+y2);
if(i==j)
map[j][i]=map[i][j]=;
else
map[i][j]=map[j][i]=dis;
}
prim(n);
}
return ;
}

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. iOS-开发日志-UIimageView

      UIImageView属性   1.Image 设置图片,默认显示 UIImageView *_imageView = [[UIImageView alloc]init]; _imageView. ...

  2. mongodb下载及安装配置教程【仅供参考】

    1 下载 下载页面地址:https://www.mongodb.org/downloads 版本选择:电脑系统是64位的,所以我选择了 Windows 64-bit 2008 R2+ ,msi包 2 ...

  3. utf8转为gb2312的函数

    from:http://blog.csdn.net/qianguozheng/article/details/46429245 // 代码转换操作类 class CodeConverter { pri ...

  4. ECMAScript位操作符

    在ECMAScript中,有少数的几个操作符可以对二进制位进行直接操作,这几个操作符本身直接对二进制进行操作,所有它们的本身是非常效率的,学习这一段有助于以后的优化以及理解. ECMAScript中采 ...

  5. php 加载函数 __autoload(), spl_autoload_register()

    来自:http://www.cnblogs.com/myluke/archive/2011/06/25/2090119.html spl_autoload_register (PHP 5 >= ...

  6. demo_07选择器练习

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  7. express cookie-session解惑

    express的中间件基于connect模块而来,所以相关文档可以直接参考 http://www.senchalabs.org/connect/ 使用cookie-session中间件过程中,比较困惑 ...

  8. wdcp日志

    apache或nginx都有开关默认日志,一个是正常访问日志,一个是错误的日志,目录在 /www/wdlinux/nginx-1.0.15/logs /www/wdlinux/httpd-2.2.22 ...

  9. Python学习笔记——几种数据类型

    1. 列表list: Python内置的一种数据类型是列表:list,用中括号[]表示.list是一种有序的集合,可以随时添加和删除其中的元素,而且元素的类型不必相同.list可以通过下标来访问,范围 ...

  10. Scala的Option类型

    Scala的Option类型 为了让所有东西都是对象的目标更加一致,也为了遵循函数式编程的习惯,Scala鼓励你在变量和函数返回值可能不会引用任何值的时候使用Option类型.在没有值的时候,使用No ...