MPI Maelstrom

总时间限制: 
1000ms

内存限制: 
65536kB
描述
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.''

输入
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.

输出
Your program should output the minimum communication time required to broadcast a message from the first processor to all the other processors.
样例输入
5
50
30 5
100 20 50
10 x x 10
样例输出
35
来源
East Central North America 1996
题意:有N个处理器要传信息,处理器给自己传信息不需要时间,两个人互相传信息花费时间相等。问:从第一个处理器传信息到其他所有处理器所用的最短时间。用邻接矩阵输入处理器传信息的时间,如果两台处理器不能传信息就输入‘x’。
思路:裸的单元最短路径,可以用SPFA、Dijkstra。因为数据很小,N最大才是100,所以甚至可以用Floyd做。(身为蒟蒻的我只能用Floyd大暴力QAQ)
注意: 输入有点坑,要用读入优化或algorithm里的一种神奇函数atoi(),将字符转为整型。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int n,ans,i,j,k,e[][];
int read()
{
int x=;
char ch=getchar();
while(ch<''||ch>'') {if(ch=='x') return ;ch=getchar();}
while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}
return x;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(e,,sizeof(e));
char s[];
for(i=;i<=n;i++)
for(j=;j<i;j++)
e[i][j]=e[j][i]=read();
ans=-;
for(k=;k<=n;k++)
for(i=;i<=n;i++)
for(j=;j<=n;j++)
if(e[i][k]+e[k][j]<e[i][j])
e[i][j]=e[i][k]+e[k][j];
for(i=;i<=n;i++)
if(e[][i]>ans)
ans=e[][i];
printf("%d\n",ans);
}
return ;
}

MPI Maelstrom(East Central North America 1996)(poj1502)的更多相关文章

  1. poj 2732 Countdown(East Central North America 2005)

    题意:建一个家庭树,找出有第d代子孙的名字,按照要求的第d代子孙的数从大到小输出三个人名,如果有一样大小子孙数的,就按字母序从小到大将同等大小的都输出,如果小于三个人的就全输出. 题目链接:http: ...

  2. 2017-2018 ACM-ICPC East Central North America Regional Contest (ECNA 2017) Solution

    A:Abstract Art 题意:给出n个多边形,求n个多边形分别的面积和,以及面积并 思路:模板 #include <bits/stdc++.h> using namespace st ...

  3. Gym-101673 :East Central North America Regional Contest (ECNA 2017)(寒假自训第8场)

    A .Abstract Art 题意:求多个多边形的面积并. 思路:模板题. #include<bits/stdc++.h> using namespace std; typedef lo ...

  4. POJ 1240 Pre-Post-erous! && East Central North America 2002 (由前序后序遍历序列推出M叉树的种类)

    题目链接 问题描述 : We are all familiar with pre-order, in-order and post-order traversals of binary trees. ...

  5. 2014-2015 ACM-ICPC East Central North America Regional Contest (ECNA 2014) A、Continued Fractions 【模拟连分数】

    任意门:http://codeforces.com/gym/100641/attachments Con + tin/(ued + Frac/tions) Time Limit: 3000/1000 ...

  6. East Central North America 2006 Hie with the Pie /// 状压dp oj22470

    题目大意: 输入n,有n个地方(1~n)需要送pizza pizza点为0点 接下来n+1行每行n+1个值 表示 i 到 j 的路径长度 输出从0点到各点送pizza最后回到0点的最短路(点可重复走) ...

  7. [bfs,深度记录] East Central North America Regional Contest 2016 (ECNA 2016) D Lost in Translation

    Problem D Lost in Translation The word is out that you’ve just finished writing a book entitled How ...

  8. East Central North America Region 2015

    E 每过一秒,当前点会把它的值传递给所有相邻点,问t时刻该图的值 #include <iostream> #include <cstdio> #include <algo ...

  9. 2016-2017 ACM-ICPC East Central North America Regional Contest (ECNA 2016) F 区间dp

    Problem F Removal GameBobby Roberts is totally bored in his algorithms class, so he’s developed a li ...

随机推荐

  1. Guava cache 示例

    pom.xml <!-- guava --> <dependency> <groupId>com.google.guava</groupId> < ...

  2. 原生js获取到页面上所有的checkbox

    <!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8" ...

  3. 洛谷P3724 大佬 [AH2017/HNOI2017] dp+bfs

    正解:dp+bfs 解题报告: 传送门! 这题看起来很复杂的样子其实真的很复杂 但是仔细看一下题目,会发现其实操作只有两个目的嘛,一个是保证自己不死,一个是让对手减血 而且保证自己不死只有一种操作 而 ...

  4. eslint 在VSCode中不能使用

    在VSCode中安装号eslint插件,还是不能使用,还需安装 npm install eslint-plugin-promise --save-dev 我也不知道为什么?我现在只是用两天不到vsco ...

  5. Android Studio 下载与安装配置

    一.下载 Android Studio下载链接:http://www.android-studio.org/ 1.进入安卓中文社区官网进行下载. 2.下载完成. 二.安装与配置环境 1.选择“此电脑” ...

  6. 10.6-uC/OS-III内部任务(统计任务 OS_StatTask())

    1.这个任务能够统计总的CPU使用率(0到100%),每个任务的CPU使用率( 0到100%),每个任务的堆栈使用量. 2.统计任务在uC/OS-III中是可选的,当设置OS_CFG.H中的OS_CF ...

  7. left join 太神奇了

    概念: 把left join左边的表的记录全部找出来.系统会先用表A和表B做个笛卡儿积,然后以表A为基表,去掉笛卡儿积中表A部分为NULL的记录.最后形成你的结果. 进行左连接时,就有涉及到主表.辅表 ...

  8. DataTable 指定位置添加列

    dt.Columns.Add("id").SetOrdinal(指定位置);

  9. [vue]模拟移动端三级路由: router-link位置体现router的灵活性

    小结 router-link可以随便放 router-view显示的是父组件的直接子组件的内容 想研究下移动三级路由的逻辑, 即 router-link和router-view 点首页--点新闻资讯( ...

  10. (转)EOSIO开发(一)使用Docker构建本地环境

    前言 一直想学习EOS开发,但是不知道怎么入门.最近从GitHub上下载了源码,发现官方已经提供了完整的EOSIO开发入门教程,既然如此赶紧开始行动.今天是系列文章的第一篇,介绍如何使用Docker搭 ...