#define  _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include<string.h>
#include <malloc.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std; #define M 110
#define inf 999999999
double mat[M][M];
struct tt
{
double x,y;
}dian[M]; double prim(int n,int sta)
{
double minn,sum=,dis[M];
int mark[M],i,j,flag;
for(i=;i<n;i++)
{
dis[i]=mat[sta][i];
mark[i]=;
}
mark[sta]=;
for(i=;i<n;i++)
{
minn=inf;
for(j=;j<n;j++)
{
if(mark[j]==&&dis[j]<minn)
{
minn=dis[j];
flag=j;
}
}
mark[flag]=;
sum+=dis[flag];
for(j=;j<n;j++)
{
if(dis[j]>mat[flag][j])
dis[j]=mat[flag][j];
}
}
return sum;
} int main()
{
int n,m,i,j;
while(scanf("%d",&n)!=EOF)
{
for(i=;i<n;i++)
{
scanf("%lf%lf",&dian[i].x,&dian[i].y);
for(j=;j<i;j++)
{
mat[i][j]=mat[j][i]=sqrt((dian[i].x-dian[j].x)*(dian[i].x-dian[j].x)+(dian[i].y-dian[j].y)*(dian[i].y-dian[j].y));
}
}
printf("%.2lf\n",prim(n,));
}
return ;
}

hdu 1162 Eddy's picture(最小生成树,基础)的更多相关文章

  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 (最小生成树)(java版)

    Eddy's picture 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 ——每天在线,欢迎留言谈论. 题目大意: 给你N个点,求把这N个点 ...

  3. hdu 1162 Eddy's picture (最小生成树)

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

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

  5. HDU 1162 Eddy's picture

    坐标之间的距离的方法,prim算法模板. Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32 ...

  6. hdu 1162 Eddy's picture (prim)

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

  7. HDU 1162 Eddy's picture (最小生成树 prim)

    题目链接 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 be ...

  9. 题解报告:hdu 1162 Eddy's picture

    Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to become ...

随机推荐

  1. ZigBee安全相关

    ZigBee安全由AES加密算法和CCM操作方式作为安全方案,广泛使用在ZigBee联盟的通信协议中.ZDO层负责安全策略和安全配置的管理. Technorati 标签: ZigBee 安全 2. 配 ...

  2. 用Windows API函数(CreateFile/ReadFile/WriteFile/CloseHandle)完成文件拷贝程序(初级版)

    文件拷贝程序 程序类型:Console 参数:源文件名   目的文件名 要求:1.只能使用Windows API函数(CreateFile/ReadFile/WriteFile/CloseHandle ...

  3. 如何在Ubuntu下使用TF/SD 卡制作Exynos 4412 u-boot启动盘

    /** ****************************************************************************** * @author    Maox ...

  4. Zedboard VmodCAM PIN Constraint

    自己画了一块FMC-VHDCI四层板,外接VmodCAM,接口定义如下 #CAMA PIN CONSTRACT NET "CAMA_D_I[7]" LOC = T17 | IOST ...

  5. jquery 处理字符串 【转】

    1,去掉空格   var txt=$.trim($("txt1").val()); 2,转为数字   txtNum=Number($.trim(txt)) + 1; var thi ...

  6. php关联不上mysql解决办法

      ## php无法关联mysql  php关联不上mysql解决办法: 尝试N多方法,需要的dll文件都复制了,依旧是不断提示: Fatal error: Call to undefined fun ...

  7. struct和class区别

    转载来源:http://blog.sina.com.cn/s/blog_48f587a80100k630.html C++中的struct对C中的struct进行了扩充,它已经不再只是一个包含不同数据 ...

  8. MongoDB的分组统计 group

    mongodb中的分组聚合用$group,而且处理的最大数据量为100M如果超出需要写入到磁盘,使用格式如下: { $group: { _id: <expression>, <fie ...

  9. [转]null和""以及==与equals的区别

    String str1 = null; str引用为空 String str2 = ""; str引用为空串 直接点就是null没有分配内存空间,而""分配了内 ...

  10. 多实例MySQL批量添加用户和密码并授权

    OS:Cent OS 6.3 DB:5.5.14 如果一台服务器上有100个MySQL数据库实例,此时需要给不同端口的几个数据库添加用户名.密码并授权应用IP,一个个授权没问题,反正累的不是我,哇咔咔 ...