题意 : 给出 N 个点,各个点之间的路径长度用给出的下三角矩阵表示,上上角矩阵和下三角矩阵是一样的,主对角线的元素都是 0 代表自己到达自己不用花费,现在问你从 1 到 N 的最短路,矩阵的 x 代表点间无法互相到达

分析 : 最短路模板…… 就是在输入的时候需要将字符串变成整数、自己写也可以,也可以使用 atoi(char *)函数,其作用是将字符串数组变成整数,复杂度为 O(n)

#include<bits/stdc++.h>
using namespace std;
;
const int INF  = 0x3f3f3f3f;
typedef pair<int, int> HeapNode;

struct EDGE{ int v, nxt, w; };
int Head[maxn], Dis[maxn];
EDGE Edge[maxn*maxn];
int N, cnt;
inline void init()
{
    ; i<=N; i++)
        Head[i]=-, Dis[i]=INF;
    cnt = ;
}

inline void AddEdge(int from, int to, int weight)
{
    Edge[cnt].v = to;
    Edge[cnt].w = weight;
    Edge[cnt].nxt = Head[from];
    Head[from] = cnt++;
}

int Dijkstra(int st)
{
    priority_queue< HeapNode, vector<HeapNode>, greater<HeapNode> > Heap;
    Dis[st] = ;
    Heap.push(make_pair(, st));
    while(!Heap.empty()){
        pair<int, int> T = Heap.top(); Heap.pop();
        if(T.first != Dis[T.second]) continue;
        ; i=Edge[i].nxt){
            int Eiv = Edge[i].v;
            if(Dis[Eiv] > Dis[T.second] + Edge[i].w){
                Dis[Eiv] = Dis[T.second] + Edge[i].w;
                Heap.push(make_pair(Dis[Eiv], Eiv));
            }
        }
    }
    ;
    ; i<=N; i++)
        ret = max(ret, Dis[i]);
    return ret;
}
];
int main(void)
{

    while(~scanf("%d", &N)){
        init();
        ; i<=N; i++){
            ; j<i; j++){
                scanf("%s", Digit);
                ] != 'x'){
                    int weight = atoi(Digit);
                    AddEdge(i, j, weight);
                    AddEdge(j, i, weight);
                }
            }
        }
        printf());
    }

    ;
}

POJ 1502 MPI MaeIstrom ( 裸最短路 || atoi系统函数 )的更多相关文章

  1. POJ 1502 MPI Maelstrom(最短路)

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

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

  3. POJ 1502 MPI Maelstrom (最短路)

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

  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. POJ 1502 MPI Maelstrom (Dijkstra)

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

  7. (简单) POJ 1502 MPI Maelstrom,Dijkstra。

    Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odysse ...

  8. POJ 1502 MPI Maelstrom(模板题——Floyd算法)

    题目: BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distri ...

  9. POJ - 1502 MPI Maelstrom 路径传输Dij+sscanf(字符串转数字)

    MPI Maelstrom BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odys ...

随机推荐

  1. linux上搭建nginx+ftp,实现文件的上传与访问

    ftp服务器搭建 1.新建用户ftpuser并指定主目录为/home/ftpuser (注意:这个目录是后面存储和读取文件的目录) <!--创建用户并指定主目录--> useradd -d ...

  2. Python笔记(二十五)_魔法方法_描述符

    描述符的属性方法 __get__(self, instance, owner): 用于访问属性,返回属性的值 __set__(self, instance, value): 用于给属性赋值时,返回属性 ...

  3. K近邻实现

    1 定义画图函数,用来可视化数据分布 (注:jupyternotebook来编写的代码) import matplotlib.pyplot as plt import numpy as np %con ...

  4. Cors 跨域 共享

    CORS是一个W3C标准,全称是"跨域资源共享"(Cross-origin resource sharing). 它允许浏览器向跨源服务器,发出XMLHttpRequest请求,从 ...

  5. 000 (H5*) 常见代码

    目录: 1:HTML 1:块级元素(block-level) 2:行内元素(inline-level) 3:行内块元素(inline-block) 4: img标签 5:表单元素 6:自定义列表  d ...

  6. HDUSTOJ-1558 Flooring Tiles(反素数)

    1558: Flooring Tiles 时间限制: 3 Sec  内存限制: 128 MB提交: 59  解决: 36[提交][状态][讨论版] 题目描述 You want to decorate ...

  7. selenium 定位方式

    在使用selenium webdriver进行元素定位时,通常使用findElement或findElements方法结合By类返回的元素句柄来定位元素.其中By类的常用定位方式共八种,现分别介绍如下 ...

  8. httplib模块:(一个相对底层的http请求模块)

    httplib是一个相对底层的http请求模块,期上有专门的包装模块,如urllib内建模块,goto第三方模块,但是封装的越高就约不灵活,比如urllib模块里的请求错误是就不会返回结果页的内容,只 ...

  9. JS对象总结

    JS对象总结   复习: 1.1 JS中对象有三种:内置对象(数组Array对象.String字符串对象.RegExp正则表达式对象.Math对象). 宿主对象(JS脚本所在的运行环境,目前我们讲的脚 ...

  10. MySQL语句之数据的增删改查

    1.插入记录insert语法:INSERT INTO tablename (field1,field2,……fieldn) VALUES(value1,value2,……valuesn); 也可以一次 ...