POJ 1502 MPI Maelstrom (最短路)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 6044 | Accepted: 3761 |
Description
``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 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
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 (最短路)的更多相关文章
- POJ 1502 MPI Maelstrom [最短路 Dijkstra]
传送门 MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5711 Accepted: 3552 ...
- POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom /ZOJ 1291 MPI Maelstrom (最短路径)
POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom ...
- POJ 1502 MPI Maelstrom(最短路)
MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4017 Accepted: 2412 Des ...
- POJ 1502 MPI Maelstrom
MPI Maelstrom Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) Total ...
- POJ - 1502 MPI Maelstrom 路径传输Dij+sscanf(字符串转数字)
MPI Maelstrom BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odys ...
- POJ 1502 MPI Maelstrom (Dijkstra)
题目链接:http://poj.org/problem?id=1502 题意是给你n个点,然后是以下三角的形式输入i j以及权值,x就不算 #include <iostream> #inc ...
- (简单) POJ 1502 MPI Maelstrom,Dijkstra。
Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odysse ...
- POJ 1502 MPI Maelstrom(模板题——Floyd算法)
题目: BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distri ...
- POJ 1502 MPI Maelstrom【floyd】
题目大意:求点1到所有点最短路径的最大值 思路:水题,单源最短路,网上解题清一色dijkstra,但是点数小于100显然floyd更简洁嘛 #include<cstdio> #includ ...
随机推荐
- lighttpd fastcgi的搭建
公司很久以前有个task需要在板子上搭建个webserver以响应局域网内手机的请求. 以前是用lighttpd plugin实现的,后来仔细想想用fast cgi来弄也可以. 在install li ...
- Win7 x64下进程保护与文件保护(ObRegisterCallbacks)
进程保护部分参考 http://bbs.pediy.com/showthread.php?t=168023 进程保护,在任务管理器不能结束进程 #ifndef CXX_PROTECTPROCESSX6 ...
- 【转】Android中View的绘制过程 onMeasure方法简述 附有自定义View例子
Android中View的绘制过程 当Activity获得焦点时,它将被要求绘制自己的布局,Android framework将会处理绘制过程,Activity只需提供它的布局的根节点. 绘制过程从布 ...
- Servlet容器的启动过程
[http://book.51cto.com/art/201408/448854.htm] Tomcat的启动逻辑是基于观察者模式设计的,所有的容器都会继承Lifecycle接口,它管理着容器的整 ...
- 玩转变量、环境变量以及数学运算(shell)
变量和环境变量 var=value 给变量赋值,输出语句:$ echo $var或者是$ echo ${var},记住中间有个空格 例如:name="coffee" age ...
- 12.组合(Composition)
组合也是关联关系的一种特例,它体现的是一种contains-a的关系,这种关系比聚合更强,也称为强聚合:它同样体现整体与部分间的关系,但此时整体与部分是不可分的,它们具有统一的生存期,整体的生命周期结 ...
- EasyMock使用手记
from:http://www.blogjava.net/supercrsky/articles/162766.html Mock 对象能够模拟领域对象的部分行为,并且能够检验运行结果是否和预期的一致 ...
- windows的iis做后门,隐藏访问,无日志<转>
windows下的iis5/iis6做后门,隐藏访问,不留访问记录或者不留日志 好不容易攻下一台Windows2000/2003 IIS服务器,你一定会想,怎样才能长期占有这个“肉鸡”呢?聪明的你肯定 ...
- 一个小巧的C++Log输出到文件类 (转)
http://blog.csdn.net/dpsying/article/details/17122739 有时候需要输出一些程序运行的信息,供我们不需要调试就可以直接查看程序运行状态.所以我们需 ...
- php实现工厂模式
设计模式-使用php实现工厂方法模式 [概要] 创建型模式 定义一个用于创建对象的接口,让子类决定实例化哪一个类.Factory Method使用一个类的实例化延迟到其子类[GOF95] [结构图] ...