MPI Maelstrom(Dijkstra)
http://poj.org/problem?id=1502
刷一道模板题稳定一下心情。。。
Dijkstra求单源最短路,就是输入的时候注意下,是按下三角输入的(无向图),输入字符x表示i与j不通。
可以这样输入:
if(scanf("%d",&w)) map[i][j] = map[j][i] = w;
else scanf("x");
#include<stdio.h>
#include<string.h>
const int INF = 0x3f3f3f3f; int map[][],vis[],dis[],n;
void Dijkstra()
{
int i,j;
memset(vis,,sizeof(vis));
for(i = ; i < n; i++)
dis[i] = INF;
dis[] = ; for(i = ; i < n; i++)
{
int mindis = INF,pos;
for(j = ; j < n; j++)
{
if(!vis[j] && dis[j] < mindis)
{
mindis = dis[j];
pos = j;
}
}
vis[pos] = ;
for(j = ; j < n; j++)
{
if(!vis[j] && dis[j] > dis[pos]+map[pos][j])
dis[j] = dis[pos]+map[pos][j];
}
} } int main()
{
while(~scanf("%d",&n))
{
for(int i = ; i < n; i++)
for(int j = ; j < n; j++)
map[i][j] = INF;
for(int i = ; i < n; i++)
{
for(int j = ; j < i; j++)
{
int w;
if(scanf("%d",&w)) map[i][j] = map[j][i] = w;
else scanf("x");
}
}
Dijkstra();
int max = -;
for(int i = ; i < n; i++)
{
if(dis[i] > max)
max = dis[i];
}
printf("%d\n",max);
}
return ;
}
MPI Maelstrom(Dijkstra)的更多相关文章
- POJ 1502:MPI Maelstrom Dijkstra模板题
MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6499 Accepted: 4036 Des ...
- POJ 1502 MPI Maelstrom (Dijkstra)
题目链接:http://poj.org/problem?id=1502 题意是给你n个点,然后是以下三角的形式输入i j以及权值,x就不算 #include <iostream> #inc ...
- POJ1502 MPI Maelstrom Dijkstra
题意 给出图,从点1出发,求到最后一个点的时间. 思路 单源最短路,没什么好说的.注意读入的时候的技巧. 代码 #include <cstdio> #include <cstring ...
- POJ 1502 MPI Maelstrom [最短路 Dijkstra]
传送门 MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5711 Accepted: 3552 ...
- POJ 1502 MPI Maelstrom
MPI Maelstrom Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) Total ...
- MPI Maelstrom(East Central North America 1996)(poj1502)
MPI Maelstrom 总时间限制: 1000ms 内存限制: 65536kB 描述 BIT has recently taken delivery of their new supercom ...
- POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom /ZOJ 1291 MPI Maelstrom (最短路径)
POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom ...
- POJ 1502 MPI Maelstrom (最短路)
MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6044 Accepted: 3761 Des ...
- POJ 1502 MPI Maelstrom(最短路)
MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4017 Accepted: 2412 Des ...
随机推荐
- windows和linux双系统删除linux
装了Windows和linux双系统的朋友,在后期要删除linux是个比较头痛的问题,因为MBR已经被linux接管,本文的目的是如何在windows 和linux双系统下,简单,完美地卸载linux ...
- android反编译经验谈
反编译这事,找对了工具其实非常简单. 反编译工具下载地址http://pan.baidu.com/s/1eQvshwu android的反编译要经过两个步骤: 1.把dex文件转为jar 2.jar转 ...
- 兼容IE浏览器的placeholder【超不错】
jQuery EnPlaceholder plug (兼容IE浏览器的placeholder)使用 >>>>>>>>>>>>&g ...
- 第四篇:python 高级之面向对象初级
python 高级之面向对象初级 python 高级之面向对象初级 本节内容 类的创建 类的构造方法 面向对象之封装 面向对象之继承 面向对象之多态 面向对象之成员 property 1.类的创建 ...
- producer怎样发送消息到指定的partitions
http://www.aboutyun.com/thread-9906-1-1.html http://my.oschina.net/u/591402/blog/152837 https://gith ...
- 网站如何防Session冒名顶替和cookie防篡改
做网站难免要面对安全性的问题,诸如sql注入拉,cookie冒名拉,等等,sql注入算是老生常谈,翻翻旧账有不少优秀的帖子在说明这个问题,所以我们来说说Session冒名顶替的风险以及应对的办法. 首 ...
- 介绍TableView非常不错的一篇文章
原文:http://blog.csdn.net/fanxiaochuan/article/details/11332775 介绍TableView非常不错的一篇文章: http://www.cocoa ...
- jQuery慢慢啃筛选(四)
1.eq(index|-index) 获取第N个元素 其中负数:一个整数,指示元素的位置,从集合中的最后一个元素开始倒数.(1算起) $("p").eq(1)//获取匹配的第二个元 ...
- Mac OS X 系统下快速显示隐藏文件的方法(使用Automator创建workflow)
有的时候需要显系统中的隐藏文件,在 Mac 中不像windows系统那么方便(勾选选项就能够操作),需要在 Terminal 中执行: localhost:~ mx$ defaults write c ...
- linxu 挂载分区
1. 添加新硬盘 设置 -> Storage -> SATA控制器->右击,选择“添加虚拟硬盘” 然后,根据需求创建合适的硬盘 2. 重启虚拟机 查看现有系统的磁盘空间 sudo f ...