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>
 7 using namespace std;
 8
 9 typedef long long LL;
10 #define inf (1LL << 30) - 1
11 #define rep(i,j,k) for(int i = (j); i <= (k); i++)
12 #define rep__(i,j,k) for(int i = (j); i < (k); i++)
13 #define per(i,j,k) for(int i = (j); i >= (k); i--)
14 #define per__(i,j,k) for(int i = (j); i > (k); i--)
15
16 const int N = 110;
17 vector<pair<int,int> > G[N];
18 int val[N];
19 int vis[N];
20 int n;
21
22 int fun(string& x){
23     int sum = 0;
24
25     rep__(i,0,(int)x.length()) sum = sum * 10 + (x[i] - ‘0‘);
26
27     return sum;
28 }
29
30 void input(){
31
32     string w;
33     rep(i,2,n){
34         rep__(j,1,i){
35             cin >> w;
36
37             if(w[0] == ‘x‘) continue;
38             int W = fun(w);
39             G[i].push_back(make_pair(j,W));
40             G[j].push_back(make_pair(i,W));
41         }
42     }
43 }
44
45 int dijkstra(){
46
47     if(n == 1) return 0;
48     val[1] = 0;
49     rep(i,2,n) val[i] = inf;
50
51     rep__(i,0,(int)G[1].size()) val[G[1][i].first] = G[1][i].second;
52     vis[1] = true;
53
54     rep(i,2,n){
55
56         int x = -1;
57         int v = inf;
58
59         rep(j,1,n){
60             if(!vis[j] && v > val[j]) v = val[x = j];
61         }
62
63         if(x == -1) continue;
64         vis[x] = true;
65
66         rep__(o,0,(int)G[x].size()){
67             int v = G[x][o].first;
68             int w = G[x][o].second;
69             if(!vis[v] && val[v] > val[x] + w)
70                 val[v] = val[x] + w;
71         }
72     }
73
74     int ans = 0;
75     rep(i,2,n) ans = max(ans, val[i]);
76
77     return ans;
78 }
79
80 int main(){
81
82     ios::sync_with_stdio(false);
83     cin.tie(0);
84
85     cin >> n;
86     input();
87     cout << dijkstra() << endl;
88
89     getchar();getchar();
90     return 0;
91 }

原文地址:https://www.cnblogs.com/SSummerZzz/p/11219913.html

时间: 2024-10-13 16:18:07

kuangbin专题专题四 MPI Maelstrom POJ - 1502的相关文章

MPI Maelstrom POJ 1502

http://poj.org/problem?id=1502 题意:这是一个下三角,上三角跟下三角图形一致,(若是完整的矩阵的话, 相当于 Map[i][j] 的距离为相对应的数值)这道题也一样. 不同的是 若 显示的为 ‘x’字母时, 说明Map[i][j]为正无穷, 两个点之间不通. 现在的问题是:求1到2, 1到3, .... 1到n 之中哪条路是最短的. **** 英语真的是太渣,表示看懂题意不是一般的难啊, 但是看懂题意后真的好简单 %>_<% .. 不要再考我英语了,我诚实的说四级

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

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;

kuangbin专题专题四 Til the Cows Come Home POJ - 2387

题目链接:https://vjudge.net/problem/POJ-2387 题意:从编号为n的城市到编号为1的城市的最短路. 思路:dijkstra模板题,直接套板子,代码中我会带点注释给初学者看. 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 #include <cstdio> 5 #include <string> 6 using namespac

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