POJ 1502 MPI Maelstrom(模板题——Floyd算法)
题目:
``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
题意描述:
哇,打开时题目这么长,还是有点犹豫的,先放一下? 但是快速浏览了一下,只要看懂几个关键词就OK了。首先an adjacency matrix是邻接矩阵,然后the entries
on the (strictly) lower triangular portion of A是邻接矩阵的下三角部分,最后x表示不通。
解题思路:
最短路Floyd算法模板题,处理数据使用Floyd算法即可。
代码实现:
#include<stdio.h>
int main()
{
int n,inf=,i,j,e[][],t,k,max;
while(scanf("%d",&n) != EOF)
{
for(i=;i<=n;i++)
{
for(j=;j<=n;j++)
{
if(i==j)
e[i][j]=;
else
e[i][j]=inf;
}
}
for(i=;i<=n;i++)
{
for(j=;j<=i-;j++)
{
if(scanf("%d",&t))
e[i][j]=e[j][i]=t;
else
getchar();//字符处理技巧
}
}
for(k=;k<=n;k++)
for(i=;i<=n;i++)
for(j=;j<=n;j++)
if(e[i][j] > e[i][k] + e[k][j])
e[i][j]=e[i][k] + e[k][j];
for(max=-inf,i=;i<=n;i++)
{
if(e[][i] > max)
max=e[][i];
}
printf("%d\n",max);
}
return ;
}
易错分析:
1、这里有一个数字矩阵混合单个字符处理的小技巧,见注释。
POJ 1502 MPI Maelstrom(模板题——Floyd算法)的更多相关文章
- 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 : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) Total ...
- POJ 1502 MPI Maelstrom(最短路)
MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4017 Accepted: 2412 Des ...
- HDU 1874 畅通工程续(模板题——Floyd算法)
题目: 某省自从实行了很多年的畅通工程计划后,终于修建了很多路.不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行走的距离要短很多.这让行人很困扰 ...
- POJ 1502 MPI Maelstrom (最短路)
MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6044 Accepted: 3761 Des ...
- HDU 2544 最短路(模板题——Floyd算法)
题目: 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt.但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线,你 ...
- 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]
传送门 MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5711 Accepted: 3552 ...
- POJ 1502 MPI Maelstrom【floyd】
题目大意:求点1到所有点最短路径的最大值 思路:水题,单源最短路,网上解题清一色dijkstra,但是点数小于100显然floyd更简洁嘛 #include<cstdio> #includ ...
随机推荐
- 阅读MDN文档之层叠与继承(二)
目录 The cascade Importance Specificity Source order A note on rule mixing Inheritance Controlling inh ...
- 2017双11海量数据下EagleEye的使命和挑战
摘要: EagleEye作为阿里集团老牌的链路跟踪系统,其自身业务虽不在交易链路上,但却监控着全集团的链路状态,特别是在中间件的远程调用上,覆盖了集团绝大部分的场景,在问题排查和定位上发挥着巨大的作用 ...
- 正则表达式与grep
一.回溯引用 1.将页面中合法的标题找出来,使用回溯引用匹配 (需要使用 -E 或 -P 来扩展grep语法支持) 2.查找连续出现的单词 二.前后查找 (grep 只能使用 -P 选项) 1. 向前 ...
- Errors are values
原文地址 https://blog.golang.org/errors-are-values Go程序员之间(特别是这些刚接触Go语言的新人)一个常见的讨论点是如何处理错误.谈话经常变成为对如下代码序 ...
- [ZJOI2015]地震后的幻想乡
题目传送门 SOL:不会积分的我瑟瑟发抖. 所以我选择状压DP. 我们有以下一个dp状态: f[S][i],S表示点集,i表示这个点集向外联了i条边. 那么答案就是f[(1<<n)-1][ ...
- Python day 7(1) 模块
一:模块 1 在Python中,一个.py文件就称之为一个模块(Module) 2 Python的好处,优点: a 提高了代码的可维护性 b 当一个模块编写完毕,就可以被其他地方引用.我们在编写程 ...
- 第八章:Python基础の面向对象(二)
本課主題 面向对象的多态 面向对象的成员 成员修饰符 特殊成员 面向对象其他应用 异常处理 设计模式与单例模式 面向对象的多态 指定参数类型只是多态的一种表现 另外一种是允许自己类型和自己的子类型(典 ...
- 前端MVC Vue2学习总结(七)——ES6与Module模块化、Vue-cli脚手架搭建、开发、发布项目与综合示例
使用vue-cli可以规范项目,提高开发效率,但是使用vue-cli时需要一些ECMAScript6的知识,特别是ES6中的模块管理内容,本章先介绍ES6中的基础与模块化的内容再使用vue-cli开发 ...
- 使用fruitstrap实现命令行将IPA包安装到iOS设备上
Requirements Mac OS X. Tested on Snow Leopard only. You need to have a valid iPhone development cert ...
- Percona XtraBackup 核心文档
1. 介绍 1.1 MySQL 备份工具特性对比 Features Percona XtraBackup MySQL Enterprise backup License GPL Proprietary ...