POJ 1502 MPI Maelstrom (最短路)

时间:2022-02-23 06:28:13
MPI Maelstrom
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 6044   Accepted: 3761

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

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.

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

5
50
30 5
100 20 50
10 x x 10

Sample Output

35

难点在于理解题目到底要干什么,乱七八糟说了一大堆,核心就是让你求从第一个出发到其它点的最大距离,Floyd跑一遍。
 #include <iostream>
#include <cstdlib>
#include <cctype>
#include <cstdio>
using namespace std; const int SIZE = ;
const int INF = 0xfffffff; int N;
int G[SIZE][SIZE]; int main(void)
{
char s[];
int ans,temp; while(scanf("%d",&N) != EOF)
{
for(int i = ;i <= N;i ++)
G[i][i] = ;
for(int i = ;i <= N;i ++)
for(int j = ;j < i;j ++)
{
scanf(" %s",s);
if(s[] == 'x')
G[i][j] = G[j][i] = INF;
else
G[i][j] = G[j][i] = atoi(s);
} for(int k = ;k <= N;k ++)
for(int i = ;i <= N;i ++)
for(int j = ;j <= N;j ++)
G[i][j] = min(G[i][j],G[i][k] + G[k][j]); ans = ;
for(int i = ;i <= N;i ++)
ans = ans > G[][i] ? ans : G[][i];
printf("%d\n",ans);
} return ;
}

POJ 1502 MPI Maelstrom (最短路)的更多相关文章

  1. POJ 1502 MPI Maelstrom &lbrack;最短路 Dijkstra&rsqb;

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

  2. POJ 1502 MPI Maelstrom &sol; UVA 432 MPI Maelstrom &sol; SCU 1068 MPI Maelstrom &sol; UVALive 5398 MPI Maelstrom &sol;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: 4017   Accepted: 2412 Des ...

  4. POJ 1502 MPI Maelstrom

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

  5. POJ - 1502 MPI Maelstrom 路径传输Dij&plus;sscanf(字符串转数字)

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

  6. POJ 1502 MPI Maelstrom &lpar;Dijkstra&rpar;

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

  7. &lpar;简单&rpar; 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【floyd】

    题目大意:求点1到所有点最短路径的最大值 思路:水题,单源最短路,网上解题清一色dijkstra,但是点数小于100显然floyd更简洁嘛 #include<cstdio> #includ ...

随机推荐

  1. scikit-learn一般实例之三&colon;连接多个特征提取方法

    在很多现实世界的例子中,有很多从数据集中提取特征的方法.很多时候我们需要结合多种方法获得好的效果.本例将展示怎样使用FeatureUnion通过主成分分析和单变量选择相进行特征结合. 结合使用转换器的 ...

  2. 查看mysql的状态

    实时查看mysql状态连接数 查询数 etc mysqladmin  -uroot  -p '' -h status -i 1

  3. Codeforces Gym 100231B Intervals 线段树&plus;二分&plus;贪心

    Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...

  4. asp&period;net 配置二级域名的共享session,并实现sso单点登录

    公司最近做了一个新网站.原先网站的网址是www.xxxx.com.新做的网站要部署到info.xxxx.com.这两个网站要实现单点登录.而新老网站本身机构的原因,对于登录状态的判断,说白了就是对于s ...

  5. word-break与word-wrap

    本文列举了兼容 IE 和 FF 的换行 CSS 推荐样式,详细介绍了word-wrap同word-break的区别.  兼容 IE 和 FF 的换行 CSS 推荐样式 最好的方式是 以下是引用片段: ...

  6. String、StringBuilder和StringBuffer

    1.string不可变性 java的docs有这样一句话:Strings are constant; their values cannot be changed after they are cre ...

  7. centos安装Django之一&colon;安装openssl

    这几天在部署Django,需要安装的东西有点多,python3.pip3.openssl(pip依赖ssl环境),所以第一步是安装openssl,如何安装呢?主要有三步,随ytkah一起来看看吧 1. ...

  8. jdk自动安装java&lowbar;home 无法修改解决方法

    使用命令行修改 cmd下set java_home=D:\soft\java\jdk1.7.0_72 搞定

  9. LinkedBlockingQueue源码解析(2)

    此文已由作者赵计刚授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 3.3.public void put(E e) throws InterruptedException 原 ...

  10. springboot项目:Redis缓存使用

    保存Redis 第一步:启动类中加入注解 @EnableCaching package com.payease; import org.springframework.boot.SpringAppli ...