POJ 1502 MPI Maelstrom(最短路)
来源:互联网 发布:获取json的某个属性 编辑:程序博客网 时间:2024/05/16 10:31
MPI Maelstrom
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 5476 Accepted: 3409
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 Swigert, has asked her to benchmark the new system.
``Since the Apollo is a distributed shared memory machine, memory access and communication times are not uniform,'' Valentine told Swigert. ``Communication is fast between processors that share the same memory subsystem, but it is slower between processors that are not on the same subsystem. Communication between the Apollo and machines in our lab is slower yet.''
``How is Apollo's port of the Message Passing Interface (MPI) working out?'' Swigert asked.
``Not so well,'' Valentine replied. ``To do a broadcast of a message from one processor to all the other n-1 processors, they just do a sequence of n-1 sends. That really serializes things and kills the performance.''
``Is there anything you can do to fix that?''
``Yes,'' smiled Valentine. ``There is. Once the first processor has sent the message to another, those two can then send messages to two other hosts at the same time. Then there will be four hosts that can send, and so on.''
``Ah, so you can do the broadcast as a binary tree!''
``Not really a binary tree -- there are some particular features of our network that we should exploit. The interface cards we have allow each processor to simultaneously send messages to any number of the other processors connected to it. However, the messages don't necessarily arrive at the destinations at the same time -- there is a communication cost involved. In general, we need to take into account the communication costs for each link in our network topologies and plan accordingly to minimize the total time required to do a broadcast.''
``Since the Apollo is a distributed shared memory machine, memory access and communication times are not uniform,'' Valentine told Swigert. ``Communication is fast between processors that share the same memory subsystem, but it is slower between processors that are not on the same subsystem. Communication between the Apollo and machines in our lab is slower yet.''
``How is Apollo's port of the Message Passing Interface (MPI) working out?'' Swigert asked.
``Not so well,'' Valentine replied. ``To do a broadcast of a message from one processor to all the other n-1 processors, they just do a sequence of n-1 sends. That really serializes things and kills the performance.''
``Is there anything you can do to fix that?''
``Yes,'' smiled Valentine. ``There is. Once the first processor has sent the message to another, those two can then send messages to two other hosts at the same time. Then there will be four hosts that can send, and so on.''
``Ah, so you can do the broadcast as a binary tree!''
``Not really a binary tree -- there are some particular features of our network that we should exploit. The interface cards we have allow each processor to simultaneously send messages to any number of the other processors connected to it. However, the messages don't necessarily arrive at the destinations at the same time -- there is a communication cost involved. In general, we need to take into account the communication costs for each link in our network topologies and plan accordingly to minimize the total time required to do a broadcast.''
Input
The input will describe the topology of a network connecting n processors. The first line of the input will be n, the number of processors, such that 1 <= n <= 100.
The rest of the input defines an adjacency matrix, A. The adjacency matrix is square and of size n x n. Each of its entries will be either an integer or the character x. The value of A(i,j) indicates the expense of sending a message directly from node i to node j. A value of x for A(i,j) indicates that a message cannot be sent directly from node i to node j.
Note that for a node to send a message to itself does not require network communication, so A(i,i) = 0 for 1 <= i <= n. Also, you may assume that the network is undirected (messages can go in either direction with equal overhead), so that A(i,j) = A(j,i). Thus only the entries on the (strictly) lower triangular portion of A will be supplied.
The input to your program will be the lower triangular section of A. That is, the second line of input will contain one entry, A(2,1). The next line will contain two entries, A(3,1) and A(3,2), and so on.
The rest of the input defines an adjacency matrix, A. The adjacency matrix is square and of size n x n. Each of its entries will be either an integer or the character x. The value of A(i,j) indicates the expense of sending a message directly from node i to node j. A value of x for A(i,j) indicates that a message cannot be sent directly from node i to node j.
Note that for a node to send a message to itself does not require network communication, so A(i,i) = 0 for 1 <= i <= n. Also, you may assume that the network is undirected (messages can go in either direction with equal overhead), so that A(i,j) = A(j,i). Thus only the entries on the (strictly) lower triangular portion of A will be supplied.
The input to your program will be the lower triangular section of A. That is, the second line of input will contain one entry, A(2,1). The next line will contain two entries, A(3,1) and A(3,2), and so on.
Output
Your program should output the minimum communication time required to broadcast a message from the first processor to all the other processors.
Sample Input
55030 5100 20 5010 x x 10
Sample Output
35
Source
East Central North America 1996
大体意思没读懂,就1A了,有点惊讶。
题目大意:n台机器能相互传递传递信息,如果数位x时代表两台机器不能传递信息,求第一台机器传递到其他机器所需要的最短时间,所以只需要从求得的num[i]中找出最大的数就可以了,
输入要求:是一个三角形,第一行输入一个n,代表有n台机器,下面有n-1行,第二行有一个数代表map[2][1],第三行有两个数字,代表map[3][1],map[3][2],第四行有3个数字,代表map[4][1]......;剩下的就很简单了。
大体意思没读懂,就1A了,有点惊讶。
题目大意:n台机器能相互传递传递信息,如果数位x时代表两台机器不能传递信息,求第一台机器传递到其他机器所需要的最短时间,所以只需要从求得的num[i]中找出最大的数就可以了,
输入要求:是一个三角形,第一行输入一个n,代表有n台机器,下面有n-1行,第二行有一个数代表map[2][1],第三行有两个数字,代表map[3][1],map[3][2],第四行有3个数字,代表map[4][1]......;剩下的就很简单了。
#include<iostream>#include<stdlib.h>#include<algorithm>#include<string>#include<stdio.h>#include <climits>using namespace std;const int INF = 9999999;const int N = 201;int n,m;int map[N][N];int v[N],num[N];int strtoint(char* str){ if (str[0] == 'x') return -1; int ret = 0; while (*str) { ret = ret * 10 + *str++ - '0'; } return ret;}void dijkstra(){ int s = 1; for(int i=0;i<=n;i++) { num[i] = INF; v[i] = 0; } num[s] = 0; for(int i=1;i<n;i++) { int min = INF; int k; for(int j=1;j<=n;j++) { if(v[j] == 0 && num[j] < min) { min = num[j]; k = j; } } if(min == INF) { break; } v[k] = 1; for(int j=1;j<=n;j++) { if(v[j] == 0 && num[j] > num[k] + map[k][j]) { num[j] = num[k] + map[k][j]; } } } int ans = -1; for(int i=1;i<=n;i++) { if(num[i]!=INF && num[i]>ans) { ans = num[i]; } } cout << ans << endl;}int main(){ while(cin >> n) { for(int i=0;i<=n;i++) { for(int j=0;j<=n;j++) { map[i][j] = INF; } map[i][i] = 0; } char xx[100]; for(int i=2;i<=n;i++) { for(int j=1;j<=i-1;j++) { cin >> xx; if(xx[0] != 'x') { map[i][j] = strtoint(xx); //cout << "map[i][j] = " << map[i][j] << endl; map[j][i] = map[i][j]; } } } dijkstra(); } return 0;}
1 0
- POJ 1502 MPI Maelstrom(最短路)
- poj 1502 MPI Maelstrom(最短路)
- POJ 1502 MPI Maelstrom 最短路dijkstra
- poj 1502--MPI Maelstrom (最短路spfa)
- 【POJ】1502 MPI Maelstrom 最短路
- POJ 1502 MPI Maelstrom 最短路
- POJ 1502MPI Maelstrom BFS最短路
- 最短路spfa POJ 1502 MPI Maelstrom
- POJ 1502 MPI Maelstrom最短路问题
- POJ 1502 MPI Maelstrom【最短路】
- POJ 1502 MPI Maelstrom 最短路
- POJ-1502-MPI Maelstrom [最短路][Dijkstra]
- POJ 1502 MPI Maelstrom 【最短路(迪杰斯特拉)】
- POJ 1502 - MPI Maelstrom(单源最短路)
- MPI Maelstrom(最短路)
- MPI Maelstrom(最短路)
- POJ 1502 MPI Maelstrom (简单最短路,多种算法均可)
- POJ1502 MPI Maelstrom(最短路dijkstra)
- C# 委托实例(跨窗体操作控件)
- 链表,逆波兰表达式
- Duilib学习笔记《03》— 控件使用
- Add a Sensor to a Robot
- wordpress中把Kindeditor和Syntaxhighlighter整合在一起
- POJ 1502 MPI Maelstrom(最短路)
- .NET技术+25台服务器怎样支撑世界第54大网站
- win7 U盘安装ubuntu14.04
- vector , map , set
- CI框架学习--各种demo
- 【图像格式】 TGA格式编码详解
- Javascript构造函数简析
- C++中名字隐藏是什么?
- HDU 4268 Alice and Bob (贪心)