坐标之间的距离的方法,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-scrollview及其子类适配iOS7

    问题描述: 在iOS7之后如果在导航控制器中所属的字控制器中嵌入scrollview及其子类的视图,当scrollview的尺寸太小的话不会调用返回cell的方法.控制器的嵌套层级结构如下图所示,着重 ...

  2. Windows下管理Python安装包

    Pip:A tool for installing and managing Python packages. Pip在Python环境中的地方就相当于Ubuntu环境中的apt-get.以及Mac系 ...

  3. 学习笔记---C++析构函数心得

    1.动态分配的对象的析构函数 class man{ public: man(){ cout<<"man begin"<<endl; }; ~man(){ c ...

  4. NPOI_2.1.3-Excel中设置小数、百分比、货币、日期、科学计数法和金额大写

    在操作Excel时候一些特殊值的转换是在所难免的,下面就给出转换方法大同小异,代码如下: HSSFWorkbook hssfWorkbook = new HSSFWorkbook(); ISheet ...

  5. ubuntu 安装 桌面 awesome

    受了ubuntu 12.04自带的桌面,运行太卡了 http://www.linuxzen.com/awesometmuxgnomedoda-zao-gao-xiao-linuxzhuo-mian-h ...

  6. linux强大IDE——Geany配置说明

    今天开始用Ubuntu了(主要是为了防止自己在windows下不自觉的打游戏之类的)   刚开始用的很不习惯  找不到合适的编译器(DEV c++什么时候才能出Linux的啊)  先后下了codeli ...

  7. JBPM4 常用表结构及其说明

    本文从表结构.操作时表的变化以及jbpm4.4各个包的作用来介绍jbpm的. 第一部分:表结构说明 Jbpm4 共有18张表,如下,其中红色的表为经常使用的表   一:资源库与运行时表结构 1.  J ...

  8. WPF DataGrid 自动生成行号的方法(通过修改RowHeaderTemplate的方式)

    WPF中的DataGrid自动生成行号的方法有很多,这里记录了一种通过修改 RowHeaderTemplate的方式来生成行号: 方法一: xaml界面: <Window ... xmlns:l ...

  9. GPUImage 滤镜头文件

    #import "GLProgram.h" // Base classes #import "GPUImageOpenGLESContext.h" #impor ...

  10. 怎么利用ultraISO对一个文件夹制作ISO镜像

    1. 运行UltraISO软件,选择好需要转换成ISO的文件,直接拖到UltraISO的界面中. 2.点击“另存为”按钮,选择存放路径并写上ISO文件的名称,文件保存类型选择为ISO格式,点击“保存” ...