POJ - 1502 MPI Maelstrom 路径传输Dij+sscanf(字符串转数字)
MPI Maelstrom
``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
题意:有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(字符串转数字)的更多相关文章
- 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 [最短路 Dijkstra]
传送门 MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5711 Accepted: 3552 ...
- 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)
题目链接:http://poj.org/problem?id=1502 题意是给你n个点,然后是以下三角的形式输入i j以及权值,x就不算 #include <iostream> #inc ...
- POJ 1502 MPI Maelstrom( Spfa, Floyd, Dijkstra)
题目大意: 给你 1到n , n个计算机进行数据传输, 问从1为起点传输到所有点的最短时间是多少, 其实就是算 1 到所有点的时间中最长的那个点. 然后是数据 给你一个n 代表有n个点, 然后给你一 ...
- (简单) 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 ...
随机推荐
- function declarations are hoisted and class declarations are not 变量提升
Classes - JavaScript | MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes ...
- Swift 学习笔记 (初始化)
初始化是为类 结构体 或者枚举准备实例的过程.这个过程需要给实例里的每一个存储属性设置一个初始值并且在新实例可以使用之前执行任何其它所必需的配置或初始化. 初始化器 初始化器在创建特定类型的实例时被调 ...
- 流畅的python学习笔记:第十一章:抽象基类
__getitem__实现可迭代对象.要将一个对象变成一个可迭代的对象,通常都要实现__iter__.但是如果没有__iter__的话,实现了__getitem__也可以实现迭代.我们还是用第一章扑克 ...
- Oracle数据库基础--存储过程和函数
一.存储过程和函数 存储过程: 对一个模块的封装 函数: 功能与存储过程几乎一样 区别: 函数必须通过return 关键字返回一个值 存储过程: 不需要return返回值 参数: 输入型参数 输出型参 ...
- 数据解析,懒加载,代理ip
在前面的requests流程中,还缺少了一步重要的流程,就是在持久化存储之前需要进行制定的数据解析.因为在大多数情况下,我们都会使用聚焦爬虫,也就是爬取页面中的指定部分数据值,而不是整个页面的数据. ...
- HDU - 2102 A计划 【BFS】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2102 思路 题目有两个坑点 0.Output 说 能在T时刻 找到公主 就输出 YES 但实际上 只要 ...
- 【转】ios内联函数 inline
ios内联函数 inline 缘由 由于在学习使用UIScrollVew开发的过程中,碰到下面这个属性(设置内边距): @property(nonatomic) UIEdgeInsets scroll ...
- golang字符串拼接性能对比
对比 +(运算符).strings.Join.sprintf.bytes.Buffer对字符串拼接的性能 package main import ( "bytes" "f ...
- HDU 2138 How many prime numbers(Miller_Rabin法判断素数 【*模板】 用到了快速幂算法 )
How many prime numbers Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- Linux学习之路(三)搜索命令
1.文件搜索命令locate 2.命令搜索命令whereis与which 3.字符串搜索命令grep 4.find命令与grep命令的区别 locate命令相对于find命令搜索非常快,find命令在 ...