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. odoo权限管理

    Odoo的权限的核心是权限组(res_groups).对每个权限组,可以设置权限组的菜单表示,对象表示,记录规则表示,字段表示. 1.菜单/对象级别 设置哪些人可以访问哪些菜单/对象,对象的访问权限包 ...

  2. MonkeyRunner_模拟机_运行脚本

    1.打开创建好的Android模拟机  (使用AVD Manager.exe打开,或者使用cmd窗口 emulator -avd test2打开) 2.打开cmd窗口,输入monkeyrunner,然 ...

  3. 20165225 2017-2018-2《Java程序设计》课程总结

    20165225 2017-2018-2<Java程序设计>课程总结 - 每周作业链接汇总: 预备作业一:我期待的师生关系 预备作业二:学习基础和C语言基础调查 预备作业三:linux安装 ...

  4. redis的基本介绍

    redis是什么? redis是一种菲关系型数据库,存储key-value类型的数据. redis支持的数据类型 这里所说的数据类型其实就是value对应的数据类型.一共有五种: String 1.S ...

  5. TZOJ 5640: 数据结构实验:仓库管理

    描述 某百货公司仓库中有一批电视机,按其价格严格从低到高的次序,以链表(链表含头结点)的形式存储于计算机中,链表的每个结点表示同样价格的电视机台数.现在又有m台价格为x元的电视机准备入库,请将其加入到 ...

  6. 利用session防止表单重复提交

    转自:http://www.cnblogs.com/xdp-gacl/p/3859416.html 利用Session防止表单重复提交 对于[场景二]和[场景三]导致表单重复提交的问题,既然客户端无法 ...

  7. SQL存储过程分页

    CREATE PROC ZDY_FY(@Pages INT, @pageRow INT) --@Pages第几页 @pageRow每页显示几行 AS BEGIN DECLARE @starNum IN ...

  8. vue中常用的两中页面刷新的方式和页面回退

    这个方法的参数是一个整数,意思是在 history 记录中向前或者后退多少步,类似 window.history.go(n) router.push(location) 想要导航到不同的 URL,则使 ...

  9. PHP MYSQL 临时表的使用

    /** * 临时表:用于获取爱鸽登录分类数量 */ $temporaryTableName = uniqid('temporary_'); $model = M(); $model->execu ...

  10. vue 获取屏幕宽高 width height

    /**  * 获取屏幕宽高  */ Vue.prototype.getViewportSize = function(){   return {     width: window.innerWidt ...