题目链接: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的更多相关文章

  1. 【POJ】1502 MPI Maelstrom

    题目链接:http://poj.org/problem?id=1502 题意:一个处理器给n-1个处理器发送广播,问最短时间.广播时并发,也就是各个路径就大的一方.输入如果是x的话说明两个处理器不能相 ...

  2. 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 ...

  3. POJ 1502 MPI Maelstrom(最短路)

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4017   Accepted: 2412 Des ...

  4. POJ - 1502 MPI Maelstrom 路径传输Dij+sscanf(字符串转数字)

    MPI Maelstrom BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odys ...

  5. POJ 1502 MPI Maelstrom

    MPI Maelstrom Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) Total ...

  6. POJ 1502 MPI Maelstrom (最短路)

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6044   Accepted: 3761 Des ...

  7. POJ 1502 MPI Maelstrom [最短路 Dijkstra]

    传送门 MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5711   Accepted: 3552 ...

  8. POJ 1502 MPI Maelstrom(模板题——Floyd算法)

    题目: BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distri ...

  9. POJ 1502 MPI Maelstrom (Dijkstra)

    题目链接:http://poj.org/problem?id=1502 题意是给你n个点,然后是以下三角的形式输入i j以及权值,x就不算 #include <iostream> #inc ...

随机推荐

  1. 剑指OFFER之二叉树中和为某一值的路径(九度OJ1368)

    题目描述: 输入一颗二叉树和一个整数,打印出二叉树中结点值的和为输入整数的所有路径.路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径. 输入: 每个测试案例包括n+1行: 第一行为2 ...

  2. python学习(5)

    python(5)5.1 模块:每个.py文件就是一个模块,多个模块可以放在一个包中,而多个包可以放在更大的包中.表示包A中的asd.py可以这样写:A.asd sys模块:它是python的内建模块 ...

  3. 记一次js中和php中的字符串长度计算截取的终极问题和完美解决方案

    1.js是用unicode算长度的,比如单字节的算1,中文也算1,但是正常我们想让两个单字节算1,如何计算这个长度 第一种解决方案,用正则,如下 /[\u0x00-\u0xff]/,天真的想着,这样就 ...

  4. 作为平台的Windows PowerShell(一)

    除了作为一种脚本语言外,Windows PowerShell被多种应用程序使用.这是因为Windows PowerShell引擎可以被托管在一个应用程序内部.这篇博文和下一篇博文将会处理在C#应用程序 ...

  5. MySQL Cluster测试过程中的错误汇总--ERROR 1296 (HY000)等等

    参考资料: http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-privilege-distribution.html http://www.cl ...

  6. ABAP程序执行效率和优化 ABAP Performance Examples

    一.             SQL Interface1.         Select ... Where vs. Select + Check用Select … Where语句效率比Select ...

  7. jQuery中要注意的一些函数

    has()方法 或 :has选择器 :是过滤子类含有的,并不是过滤当前选择器选择的元素或对象含有的

  8. 10 Technologies That will Shape Future Education--reference

    http://dizyne.net/technologies-that-will-shape-future-education/ Technology is on the rise and with ...

  9. opencv中的基本拼接

    普通版的图像拼接,事实上非常简单并且效果不很差. 实现方式: 新建工程: 去opencv里面[f:\opencv249\opencv\sources\samples\cpp]把stitching.cp ...

  10. json与jsonp区别浅析(json才是目的,jsonp只是手段)

    一言以蔽之,json返回的是一串数据:而jsonp返回的是脚本代码(包含一个函数调用): JSON其实就是JavaScript中的一个对象,跟var obj={}在质上完全一样,只是在量上可以无限扩展 ...