MPI Maelstrom POJ 1502

http://poj.org/problem?id=1502

题意:这是一个下三角,上三角跟下三角图形一致,(若是完整的矩阵的话, 相当于 Map[i][j] 的距离为相对应的数值)这道题也一样。 不同的是 若 显示的为 ‘x’字母时, 说明Map[i][j]为正无穷, 两个点之间不通。 现在的问题是:求1到2, 1到3, .... 1到n 之中哪条路是最短的。

****

英语真的是太渣,表示看懂题意不是一般的难啊, 但是看懂题意后真的好简单 %>_<% 。。

不要再考我英语了,我诚实的说四级还没过  %>_<%。。。

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<algorithm>
using namespace std;

#define maxn 110
#define oo 0x3f3f3f3f
int maps[maxn][maxn], v[maxn], dist[maxn];
int n;

void Init()
{
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            if(i==j)
                maps[i][j] = 0;
            else
                maps[i][j] = maps[j][i] = oo;
        }
    }
}

void Dij()
{
    memset(v, 0, sizeof(v));
    memset(dist, 0, sizeof(dist));
    for(int i=1; i<=n; i++)
        dist[i] = maps[1][i];
        v[1] = 1;

    for(int i=1; i<n; i++)
    {
        int index, mins = oo;

        for(int j=1; j<=n; j++)
        {
            if(!v[j] && dist[j] <mins)
            {
                index = j;
                mins = dist[j];
            }
        }

        v[index] = 1;

        for(int j=1; j<=n; j++)
        {
          if(dist[j] > mins + maps[index][j] && !v[j])
            dist[j] = mins + maps[index][j];
        }
    }

    int ans = 0;
     for(int i=1; i<=n; i++)
        ans = max(ans, dist[i]);

    printf("%d\n", ans);
}

int main()
{
    char str[maxn];
    int num;

    while(scanf("%d", &n)!=EOF)
    {

         Init();

        for(int i=2; i<=n; i++)
        {
            for(int j=1; j<i; j++)
            {
                scanf("%s", str);
               if(str[0] != ‘x‘)
               {
                   sscanf(str, "%d", &num);
                   maps[i][j] = maps[j][i] = min(maps[i][j], num);
               }
            }
        }

        Dij();

    }

    return 0;
}

 

时间: 2024-07-30 10:12:48

MPI Maelstrom POJ 1502的相关文章

MPI Maelstrom POJ - 1502 最短路Dijkstra

BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchical communication subsystem. Valentine McKee's research advisor, Jack Swigert, has asked her to benchmark the

kuangbin专题专题四 MPI Maelstrom POJ - 1502

题目链接:https://vjudge.net/problem/POJ-1502 dijkstra板子题,题目提供下三角情况,不包含正对角线,因为有题意都为0,处理好输入,就是一个很水的题. 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 #include <cstdio> 5 #include <string> 6 #include <vector&g

MPI Maelstrom POJ - 1502 floyd

#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> using namespace std; const int N=110; const int INF = 0x3f3f3f3f; char s[20]; int n; int f[N][N]; void init() { for(int i = 1 ; i <= n ; i++) for(int j = 1;

POJ 1502 MPI Maelstrom (Dijkstra 模板题)

MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5877   Accepted: 3654 Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchic

poj 1502 MPI Maelstrom(最短路)

poj 1502 MPI Maelstrom Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchical communication subsystem. Valentine McKee's research advisor, Jack Swige

poj 1502 MPI Maelstrom Dijkstra算法的简单运用 ,呵呵,,我估计有很多人都没看懂什么意思,我也看了很久

MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5831   Accepted: 3621 Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchic

POJ 1502 MPI Maelstrom (最短路)

MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6329   Accepted: 3925 Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchic

POJ 1502 MPI Maelstrom [最短路 Dijkstra]

传送门 MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5711   Accepted: 3552 Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierar

POJ 1052 MPI Maelstrom

MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5547   Accepted: 3458 Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchic