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)的更多相关文章

  1. POJ 1502:MPI Maelstrom Dijkstra模板题

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6499   Accepted: 4036 Des ...

  2. POJ 1502 MPI Maelstrom (Dijkstra)

    题目链接:http://poj.org/problem?id=1502 题意是给你n个点,然后是以下三角的形式输入i j以及权值,x就不算 #include <iostream> #inc ...

  3. POJ1502 MPI Maelstrom Dijkstra

    题意 给出图,从点1出发,求到最后一个点的时间. 思路 单源最短路,没什么好说的.注意读入的时候的技巧. 代码 #include <cstdio> #include <cstring ...

  4. POJ 1502 MPI Maelstrom [最短路 Dijkstra]

    传送门 MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5711   Accepted: 3552 ...

  5. POJ 1502 MPI Maelstrom

    MPI Maelstrom Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) Total ...

  6. MPI Maelstrom(East Central North America 1996)(poj1502)

    MPI Maelstrom 总时间限制:  1000ms 内存限制:  65536kB 描述 BIT has recently taken delivery of their new supercom ...

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

  8. POJ 1502 MPI Maelstrom (最短路)

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6044   Accepted: 3761 Des ...

  9. POJ 1502 MPI Maelstrom(最短路)

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4017   Accepted: 2412 Des ...

随机推荐

  1. shell入门之变量测试 分类: 学习笔记 linux ubuntu 2015-07-10 15:49 31人阅读 评论(0) 收藏

    格式:test 测试条件 字符串测试: 注意空格: test str1 == str2 测试字符串是否相等 test str1 != str2 测试字符串是否不相等 test str1 测试字符串是否 ...

  2. Codeforces 552E - Vanya and Brackets【表达式求值】

    给一个只有加号和乘号的表达式,要求添加一对括号使得最后结果最大.表达式长度5000,乘号最多12个,表达式中数字只有1位. 左括号一定在乘号右边,右括号一定在乘号左边,因为如果不是这样的话,一定可以调 ...

  3. Python开发【第二十二篇】:Web框架之Django【进阶】

    Python开发[第二十二篇]:Web框架之Django[进阶]   猛击这里:http://www.cnblogs.com/wupeiqi/articles/5246483.html 博客园 首页 ...

  4. hdu 3450 Counting Sequences

    /* n*n暴力 这个很好想 */ #include<cstdio> #define maxn 100010 #define mod 9901 using namespace std; i ...

  5. 给Sublime Text2安装轻量级代码提示插件:SublimeCodeIntel

    步骤: 1.下载SublimeCodeIntel(地址https://github.com/SublimeCodeIntel/SublimeCodeIntel): 2.将下载的压缩包解压,并放置在Pa ...

  6. U3D 内置对象

    在U3D里面提供了一个Time对象: void OnGUI(){ Debug.Log("########################"); GUILayout.Label (& ...

  7. TCP与UDP区别

    原文链接:http://blog.sina.com.cn/s/blog_493309600100clrw.html TCP与UDP区别 TCP---传输控制协议,提供的是面向连接.可靠的字节流服务.当 ...

  8. reflact中GetMethod方法的使用

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...

  9. 提供他人class文件

    1.考虑的问题,提供的文件是否依赖于其他jar包. 例如:解析html简历时,依赖于Jsoup包.

  10. OC中的SEL解析

    OC中的SEL对象即selector对象,用来保存一个方法的地址.下面通过一个Demo来解析SEL的原理.创建一个Person类,Person.h中: #import <Foundation/F ...