(简单) POJ 1502 MPI Maelstrom,Dijkstra。
Description
``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.''
#include<iostream>
#include<cstring>
#include<cstdio> using namespace std; const int MaxN=;
const int INF=10e8; bool vis[MaxN]; void Dijkstra(int cost[][MaxN],int lowcost[],int n,int start)
{
for(int i=;i<=n;++i)
{
vis[i]=;
lowcost[i]=INF;
}
lowcost[start]=; for(int j=;j<=n;++j)
{
int k=-;
int minn=INF; for(int i=;i<=n;++i)
if(!vis[i] && lowcost[i]<minn)
{
minn=lowcost[i];
k=i;
} if(k==-)
break; vis[k]=; for(int i=;i<=n;++i)
if(!vis[i])
lowcost[i]=min(lowcost[k]+cost[k][i],lowcost[i]);
}
} int ans[MaxN];
int map1[MaxN][MaxN]; int main()
{
int n;
int maxn;
char c[]; while(~scanf("%d",&n))
{
for(int i=;i<=n;++i)
for(int j=;j<=i;++j)
if(i==j)
map1[i][j]=;
else
{
scanf("%s",c); if(c[]!='x')
sscanf(c,"%d",&map1[i][j]);
else
map1[i][j]=INF; map1[j][i]=map1[i][j];
} Dijkstra(map1,ans,n,); maxn=-; for(int i=;i<=n;++i)
if(ans[i]>maxn)
maxn=ans[i]; cout<<maxn<<endl;
} return ;
}
(简单) POJ 1502 MPI Maelstrom,Dijkstra。的更多相关文章
- POJ 1502 MPI Maelstrom (Dijkstra)
题目链接:http://poj.org/problem?id=1502 题意是给你n个点,然后是以下三角的形式输入i j以及权值,x就不算 #include <iostream> #inc ...
- 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 [最短路 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: 4017 Accepted: 2412 Des ...
- POJ 1502 MPI Maelstrom (最短路)
MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6044 Accepted: 3761 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( Spfa, Floyd, Dijkstra)
题目大意: 给你 1到n , n个计算机进行数据传输, 问从1为起点传输到所有点的最短时间是多少, 其实就是算 1 到所有点的时间中最长的那个点. 然后是数据 给你一个n 代表有n个点, 然后给你一 ...
- POJ 1502 MPI Maelstrom(模板题——Floyd算法)
题目: BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distri ...
随机推荐
- JavaBean技术的一些讲解
JavaBean: 由于原先的jsp的html代码和css代码以及java代码都是写在一起的,所以看起来就比较冗余,同时 也体现不了javaBean中面向对象的思想的{当然可以同过jstl标签库以及m ...
- Stammering Aliens
Stammering Aliens Time Limit: 2000MS Memory Limit: 65536K Description Dr. Ellie Arroway has ...
- st-Spanning Tree
st-Spanning Tree time limit per test 4 seconds memory limit per test 256 megabytes input standard in ...
- @property(nonatomic) UIViewAutoresizing autoresizingMask;
在 UIView 中有一个autoresizingMask的属性,它对应的是一个枚举的值(如下),属性的意思就是自动调整子控件与父控件中间的位置,宽高. 1 2 3 4 5 6 7 8 9 enum ...
- 构建一个最简单的web应用并部署及启动
第一种构建方式:不使用maven File-new-Dynamic Web Project,用这种方式构建的web项目是在web.xml文件中配置了welcome-file的,但是却没有对应的文件,所 ...
- iOS 常用代码块
1.判断邮箱格式是否正确的代码: // 利用正则表达式验证 -( BOOL )isValidateEmail:( NSString *)email { NSString *emailRegex ...
- 在Activity之间使用Intent传值和Bundle传值的区别和方式
两者本质上没有任何区别.Bundle只是一个信息的载体 将内部的内容以键值对组织 Intent负责Activity之间的交互 自己是带有一个Bundle的Intent.putExtras(Bundle ...
- html5 localStorage和sessionStorage
该随便来自: http://www.cnblogs.com/yuzhongwusan/archive/2011/12/19/2293347.html html5中的Web Storage包括了两种存储 ...
- Android如何使用API
转自:http://www.cnblogs.com/vanezkw/archive/2012/07/03/2574559.html 本文针对Android开发如何使用API文档进行一些经验分享. 1. ...
- hdu_5418_Victor and World(状压DP+Floyd)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5418 题意:给你n个点,和一些边,找一条路径经过全部的点,并回到起点,问最小的花费是多少, 题解:m& ...