HDU 1162 Eddy's picture
坐标之间的距离的方法,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
Input contains multiple test cases. Process to the end of file.
#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的更多相关文章
- 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 ...
- hdu 1162 Eddy's picture(最小生成树算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...
- HDU 1162 Eddy's picture (最小生成树)(java版)
Eddy's picture 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 ——每天在线,欢迎留言谈论. 题目大意: 给你N个点,求把这N个点 ...
- hdu 1162 Eddy's picture (最小生成树)
Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- hdu 1162 Eddy's picture (prim)
Eddy's pictureTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1162 Eddy's picture (最小生成树 prim)
题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...
- HDU 1162 Eddy's picture (最小生成树 普里姆 )
题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...
- 题解报告:hdu 1162 Eddy's picture
Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to become ...
- hdu 1162 Eddy's picture(最小生成树,基础)
题目 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<string.h> #include <ma ...
随机推荐
- 初尝 Perl
本文将阐述以下几方面内容: 1.什么是Perl 2.Perl有什么用 3.Windows 下的Perl环境搭建 4.Perl 版Hello World 5.Perl 语法梗概 6.一些参考资料 什么是 ...
- PHP学习笔记(七)
<wordpress 50个过滤钩子> 11-20 11.gettext: 过滤wordpress的翻译数据. 在wordpress中,使用__(), _e(), _x(), _ex(), ...
- 设置表格边框css样式
table{ width:70%; text-align:center; border-left:#C8B9AE solid 1px; border-top:#C8B9AE solid 1px; bo ...
- 【制作镜像】virsh
首先进入到图形界面 常用virsh指令: 1)virsh list 列出当前虚拟机列表,不包括未启动的 2)virsh list --all 列出所有虚拟机,包括所有已经定义的虚拟机 3)virsh ...
- OpenJudge 2787 算24
1.链接地址: http://poj.org/problem?id=1631 http://bailian.openjudge.cn/practice/2787/ 2.题目: 总时间限制: 3000m ...
- [翻译][MVC 5 + EF 6] 4:弹性连接和命令拦截
原文:Connection Resiliency and Command Interception with the Entity Framework in an ASP.NET MVC Applic ...
- MongoDB笔记(二)访问权限
要访问数据库,那么对访问权限的设置是必须的! 1.启用权限控制(-auth),当启用MongoDB数据库服务时,对参数的设置可以决定是否启用权限控制 不开启: mongod -dbpath=D:/ ...
- As3 里的正则相关
用正则的时候 不要用if(content.match("test").length > 0) ...; 改成 if(content.match(/test/g).length ...
- 学一点 mysql 双机异地热备份----快速理解mysql主从,主主备份原理及实践
双机热备的概念简单说一下,就是要保持两个数据库的状态 自动同步.对任何一个数据库的操作都自动应用到另外一个数据库,始终保持两个数据库数据一致. 这样做的好处多. 1. 可以做灾备,其中一个坏了可以切换 ...
- c++模板实例化的一个例子
以下是c++模板实例化的一个例子,虽然ObjectList::clear()里面调用的test()函数是没有定义的,但是以下代码能够编译通过,可见ObjectList::clear()未编译: tem ...