MPI Maelstrom

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

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

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

5
50
30 5
100 20 50
10 x x 10

Sample Output

35

题意:有n台机器,两两之间的数据传输速度是一样的。现在给出一张下三角形,表示机器两两之间的传输时间,x表示两机器间无法传输数据,求一号机器传输数据到其他机器的最小时间。

思路:先求一一号机器为起点到其他各点的最短路,然后取其中最大值,就是答案

#include<stdio.h>
#include<string.h>
#include<limits.h>
#include<vector>
#include<queue>
using namespace std; struct Node{
int v,w;
friend bool operator<(Node a,Node b)
{
return a.w>b.w;
}
}node; vector<Node> a[];
int dis[];
int n; void dij(int k)
{
int v1,v2,i;
priority_queue<Node> q;
dis[k]=;
node.w=;
node.v=k;
q.push(node);
while(q.size()){
v1=q.top().v;
q.pop();
for(i=;i<a[v1].size();i++){
v2=a[v1][i].v;
if(dis[v2]>dis[v1]+a[v1][i].w){
dis[v2]=dis[v1]+a[v1][i].w;
node.w=dis[v2];
node.v=v2;
q.push(node);
}
}
}
} int main()
{
int t,x,y,z,i,j;
char s[];
scanf("%d",&n);
for(i=;i<=n;i++){
a[i].clear();
dis[i]=INT_MAX;
}
for(i=;i<=n;i++){
for(j=;j<=i-;j++){
scanf(" %s",s); //空格等价getchar()
if(s[]!='x'){
sscanf(s,"%d",&x); //字符串转数字,若含多个数字可sscanf(s,"%d %d",&x,&y);
node.w=x;
node.v=i;
a[j].push_back(node);
node.v=j;
a[i].push_back(node);
}
}
}
dij();
int max=;
for(i=;i<=n;i++){
if(dis[i]>max) max=dis[i];
}
printf("%d\n",max);
return ;
}

POJ - 1502 MPI Maelstrom 路径传输Dij+sscanf(字符串转数字)的更多相关文章

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

  2. POJ 1502 MPI Maelstrom(最短路)

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

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

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

  4. POJ 1502 MPI Maelstrom

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

  5. POJ 1502 MPI Maelstrom (最短路)

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

  6. POJ 1502 MPI Maelstrom (Dijkstra)

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

  7. POJ 1502 MPI Maelstrom( Spfa, Floyd, Dijkstra)

    题目大意: 给你 1到n ,  n个计算机进行数据传输, 问从1为起点传输到所有点的最短时间是多少, 其实就是算 1 到所有点的时间中最长的那个点. 然后是数据 给你一个n 代表有n个点, 然后给你一 ...

  8. (简单) POJ 1502 MPI Maelstrom,Dijkstra。

    Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odysse ...

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

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

随机推荐

  1. 使用ab 进行并发压力测试

    使用ab 进行并发压力测试 - 参与商 - 博客园 https://www.cnblogs.com/shenshangzz/p/8340640.html 使用ab 进行并发压力测试   ab全称为:a ...

  2. install_driver(mysql) failed

        安装好了mysql监控神器innotop,正得意,innotoop不可用,其错误提示为install_driver(mysql) failed: Can't load '/usr/lib64/ ...

  3. rails debug

    =debug @thesis config下配置 东西需要重启之后才管用

  4. Spring Boot2.0之 yml的使用

    yml Spring Boot 默认读取   .yml   .properties 结尾的 yml非常好的作用,比properties更节约  结构清晰 server: port:  8090 con ...

  5. math worksheet作业纸生成器

    https://www.education.com/worksheet-generator/math/ https://www.mathgoodies.com/worksheets/generator ...

  6. 【Java】CookieStore 类使用示例

    CookieStore 是 Java API 中用来处理 HTTP 客户端的 Cookie 存储策略的类.psd素材 1. [代码]WebClient.java      01import java. ...

  7. BZOJ 3251 树上三角形:LCA【构成三角形的结论】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3251 题意: 给你一棵树,n个节点,每个点的权值为w[i]. 接下来有m个形如(p,a,b ...

  8. html5--1.11列表

    html5--1.11列表 学习要点: 无序列表 有序列表 列表的属性 自定义列表 1.无序列表的基本格式 ul(unorder line)标签里面放li标签就好了,每一项就是一个li(LineIte ...

  9. (转)C/C++——auto,static,register,extern用法

    转自:https://blog.csdn.net/u010757264/article/details/49932829 C++中变量.函数的属性包括数据类型和存储类别.存储类别分为静态存储和动态存储 ...

  10. codeforces 660A A. Co-prime Array(水题)

    题目链接: A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input stand ...