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 ...
随机推荐
- css 权威指南笔记( 五)结构和层叠
特殊性 重要性 !important; 继承 向上传播例外,应用到body元素的背景样式可以传递到html元素,相应对的可以定义其画布. 大多数框模型属性(包括外边距.内边距.背景.边框)都不能继承 ...
- Java——(一)一切都是对象
------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------- 一.用引用操纵对象 在java中一切都被视为对象,但操纵的标识符实际上是对象的一个“引用”( ...
- iOS viewController 和 view 的创建消失生命周期总结
控制器创建的生命周期 1. 如果从stroryBoard 中产生一个controller,那么会先调用initWithCoder:, awakeFromNib, loadView,viewDidLoa ...
- HDU 4288 Coder(线段树)
题意: 给定三种操作 1. add x 向序列中添加x,添加之后序列还保持有序 2. del x 删除序列中值为x的元素 3. sum 求下边模5等于3的元素和 思路: 直接暴力也可以过,就是看暴 ...
- 传统的log4j实战
/** * */ package log4j; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator ...
- power desinger 学习笔记<一>
如果一张表有 很多字段(多于30个),那么一个一个复制粘贴,耗时耗力.可以偷懒,事先编辑好 sql脚本,然后把sql脚本导入 power designer,是不是很方便? 看下面的 1. 打开Pow ...
- 一个初学者对CLSA.NET框架的使用心得
什么是CSLA.NET框架? 今天在一个群里,有人问我什么是CSLA.NET,CSLA是Component-based, Scalable, Logical Architecture的简写,CSLA ...
- Java hashCode 和 equals()
1 Object中定义的hashCode() public int hashCode() Returns a hash code value for the object. This method i ...
- Spring中的创建与销毁
在bean中添加属性init-method="方法名" destroy-method="方法名" init-method 该方法是由spring容 ...
- 在Lufylegend中如何设置bitmap或者sprite的缩放和旋转中心
最近两天有个lufylegend游戏引擎群的群友需要做一个项目,其中要解决的需求是:获取照相机拍摄的图片,根据图片的EXIF信息让图片显示为“正常”情况,并且需要给图片添加一些事件侦听.何为正常呢?就 ...