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 ...
随机推荐
- java中final与static的使用场景
final Java关键词final有“无法改变”的含义,主要用于修饰非抽象类.方法或者变量.使用时注意: final类不能被继承,没有子类,final类中的方法默认是final的. final方法不 ...
- php标准库DirectoryIterator类的操作说明
<?php $dir = new DirectoryIterator(dirname(__FILE__)); foreach ($dir as $fileInfo) { if ($fileInf ...
- python get post模拟请求
1.使用get方式时.url相似例如以下格式: &op=bind GET报问头例如以下: &n=asa HTTP/1.1 Accept: */* Accept-Lang ...
- sap crm 常用表
[转自 http://blog.csdn.net/zhongguomao/article/details/6714616] SAP CRM 参数文件集目标组常用表: CRMD_MKTTG_TG_T C ...
- ubuntu在vim里搜索关键字
在命令模式下敲斜杆( / )这时在状态栏(也就是屏幕左下脚)就出现了 “/” 然后输入你要查找的关键字敲回车就可以了. 如果你要继续查找此关键字,敲字符 n 就可以继续查找了.
- Object.create用法
用法: Object.create(object, [,propertiesObject]) 创建一个新对象,继承object的属性,可添加propertiesObject添加属性,并对属性作出详细解 ...
- android使用mina需要注意的问题
1.第三方jar包的使用 如果在Java Build Path中使用Add External JARs这种方式,运行时会有找不到类的错误(我的上面有,如果你没出现,恭喜你),上网查了几种方 ...
- css3线性渐变兼容
火狐浏览器: background:-moz-linear-gradient(top, red, rgba(0, 0, 255, 0.5)); 谷歌: .l6{background: -webkit- ...
- kvm初体验之五:vm连接网络的两种方式:bridge和nat
1. 在安装vm时指定网络连接方式 1)bridge virt-install --name vm1 --ram=1024 --vcpus=1 --disk path=/vm-images/vm1,s ...
- app测试点-1
一.安全测试 1.软件权限 1)扣费风险:包括短信.拨打电话.连接网络等. 2)隐私泄露风险:包括访问手机信息.访问联系人信息等. 3)对App的输入有效性校验.认证.授权.数据加密等方面进行检测 4 ...