(poj)1502 MPI Maelstrom
题目链接:http://poj.org/problem?id=1502
Description BIT has recently taken delivery of their new supercomputer, a 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- processors, they just do a sequence of n- 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 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 <= n <= . 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) = for <= 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(,). The next line will contain two entries, A(,) and A(,), and so on.
Output Your program should output the minimum communication time required to broadcast a message from the first processor to all the other processors.
Sample Input
Sample Output
题意:题意不好读懂,求什么从1号点到其他各点的最小距离的最大值
1--->2 35
1--->3 30
1--->4 20
1--->5 10 所以就是35…………
x表示两点之间不通
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <math.h>
#include <vector>
using namespace std;
#define N 1010
#define ll long long
#define INF 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof(a));
vector<vector<int> >Q;
int n,dis[N],vis[N],Map[N][N];
void init()
{
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
Map[i][j]=i==j?:INF;
}
met(vis,);
}
void dij()
{
for(int i=; i<=n; i++)
{
dis[i]=INF;
}
dis[]=;
for(int i=; i<=n; i++)
{
int ans=INF,k=;
for(int j=; j<=n; j++)
if(!vis[j] && ans>=dis[j])
ans=dis[k=j];
vis[k]=;
for(int j=; j<=n; j++)
if(!vis[j] && dis[j]>dis[k]+Map[k][j])
dis[j]=dis[k]+Map[k][j];
}
}
int main()
{
char m[];
while(scanf("%d",&n)!=EOF)
{
init();
for(int i=; i<=n; i++)
{
for(int j=; j<i; j++)
{
scanf("%s",m);
if(m[]!='x')
Map[i][j]=Map[j][i]=atoi(m);
}
}
dij();
int ans=;
for(int i=; i<=n; i++)
{
ans=max(ans,dis[i]);
}
printf("%d\n",ans);
}
return ;
}
(poj)1502 MPI Maelstrom的更多相关文章
- 【POJ】1502 MPI Maelstrom
题目链接:http://poj.org/problem?id=1502 题意:一个处理器给n-1个处理器发送广播,问最短时间.广播时并发,也就是各个路径就大的一方.输入如果是x的话说明两个处理器不能相 ...
- 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 路径传输Dij+sscanf(字符串转数字)
MPI Maelstrom BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odys ...
- 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: 6044 Accepted: 3761 Des ...
- POJ 1502 MPI Maelstrom [最短路 Dijkstra]
传送门 MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5711 Accepted: 3552 ...
- POJ 1502 MPI Maelstrom(模板题——Floyd算法)
题目: BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distri ...
- POJ 1502 MPI Maelstrom (Dijkstra)
题目链接:http://poj.org/problem?id=1502 题意是给你n个点,然后是以下三角的形式输入i j以及权值,x就不算 #include <iostream> #inc ...
随机推荐
- Java的面向对象思想
多态性: 一种方法有多种实现,采用哪一种实现由Java虚拟机在运行时动态决定,这种能力成为动态绑定(dynamic binding),也称为多态性(polymorphism)(源于一个希腊单词,意为“ ...
- EF中Database.SqlQuery
本文转载:http://www.cnblogs.com/daimage/archive/2012/07/04/2575844.html EF中Database.SqlQuery<TElement ...
- How to add “Maven Managed Dependencies” library in build path eclipse
If you have m2e installed and the project already is a maven project but the maven dependencies are ...
- webViewDidFinishLoad因为网页里的重定向,会调用多次,使用web view.isLoading来解决
我编码如下,但我发现 webViewDidFinishLoad() 会发生若干次. 如何知道 webViewDidFinishLoad() 最后发生吗? iNavigate = ; - (void)w ...
- Java数据抓取经验【转载】
本人担任职友集的java工程师五年,其中抓取数据占主要的一部分,抓取的信息只要有两部分,职位和简历,其中职位的抓取量为日均插入量为30万,更新量 为60万,抓取全国300多个人才网站.职友集(现在改名 ...
- linux终端或者虚拟机SecureCRT窗体拖动之后,会自己主动收到一个Ctrl+C的命令
虚拟机中SecureCRT窗体每次鼠标划动和拖动窗体都会出现Crtl+C命令.导致远程Linux连接操作中断 经查找发现是本地机器里安装了相关软件快捷键导致.比方我的有道词典划词功能.取消划词就可以
- 使用python编写批量卸载android应用的脚本
该脚本的功能是卸载android手机中安装的所有第三方应用,主要是使用adb shell pm.adb uninstall 命令,所以使用的前提是需要配好adb的环境变量,下面上代码: #!/usr/ ...
- CentOS命令行无线上网
(1)首先关闭开发板的有线网卡[root@FriendlyARM /]# ifconfig eth0 down(2)加载USB WiFi无线网卡[root@FriendlyARM /]# ifconf ...
- java_jdbc_利用结果集元数据将查询结果封装为map_MetaData
package cn.itcast.batch; import java.sql.Connection; import java.sql.ParameterMetaData; import java. ...
- 2、netlink简介
Netlink 是一种特殊的 socket,它是 Linux 所特有的,类似于 BSD 中的AF_ROUTE 但又远比它的功能强大,目前在最新的 Linux 内核(2.6.14)中使用netlink ...