MPI Maelstrom(East Central North America 1996)(poj1502)
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)的更多相关文章
- poj 2732 Countdown(East Central North America 2005)
题意:建一个家庭树,找出有第d代子孙的名字,按照要求的第d代子孙的数从大到小输出三个人名,如果有一样大小子孙数的,就按字母序从小到大将同等大小的都输出,如果小于三个人的就全输出. 题目链接:http: ...
- 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 ...
- Gym-101673 :East Central North America Regional Contest (ECNA 2017)(寒假自训第8场)
A .Abstract Art 题意:求多个多边形的面积并. 思路:模板题. #include<bits/stdc++.h> using namespace std; typedef lo ...
- 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. ...
- 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 ...
- 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点的最短路(点可重复走) ...
- [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 ...
- East Central North America Region 2015
E 每过一秒,当前点会把它的值传递给所有相邻点,问t时刻该图的值 #include <iostream> #include <cstdio> #include <algo ...
- 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 ...
随机推荐
- git知识点
先说几个名词 未被追踪的文件:指的是新建的文件或文件夹且还没加入到暂存区(新建的还没有被git add 过得) 未加入到暂存区的文件:指的是已经被追踪过,但是没有加入到暂存区(已经执行过git add ...
- LeetCode 806 Number of Lines To Write String 解题报告
题目要求 We are to write the letters of a given string S, from left to right into lines. Each line has m ...
- java ipv4校验正则字符串
String IPV4_REGEX = "\\A(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)) ...
- .net core开发工具与SDK
一.开发工具 开发工具使用Visual Studio 2017 下载官网:https://visualstudio.microsoft.com/zh-hans/vs/ 相关的安装已经有很多文章介绍过, ...
- 洛谷P2329 栅栏 [SCOI2005] 搜索
正解:搜索 解题报告: 先放下传送门! 首先说下爆搜趴,就直接枚每个需求是否被满足以及如果满足切哪个板子,随便加个最优性剪枝,似乎是有80pts 然后思考优化 首先显然尽量满足需求比较小的,显然如果能 ...
- 【Python基础】安装python第三方库
pip命令行安装(推荐) 打开cmd命令行 安装需要的第三方库如:pip install numpy 在安装python的相关模块和库时,我们一般使用“pip install 模块名”或者“pyth ...
- nginx 负载均衡5种配置方式
nginx 负载均衡5种配置方式 1.轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除. 2.weight 指定轮询几率,weight和访问比率成正比, ...
- document的全量替换、强制创建、删除
1.document的全量替换(1)语法与创建文档是一样的,PUT /test_index/test_type/id ,如果document id不存在,那么就是创建:如果document id已经存 ...
- objenesis
1.objenesis About Objenesis is a small Java library that serves one purpose: To instantiate a new ob ...
- Unity-音频系统
1.声音格式: WAV:无损,音质好,文件大,适用于短文件 OGG&&MP3: 有损,文件小,适用于较长文件,比如背景音乐