(简单) 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 ...
随机推荐
- 要想提高PHP的编程效率,你必须遵守的原则
用单引号代替双引号来包含字符串,这样做会更快一些.因为PHP会在双引号包围的字符串中搜寻变量,单引号则不会,注意:只有echo能这么做,它是一种可以把多个字符串当作参数的“函数”(译注:PHP手册中说 ...
- Segments POJ 3304 直线与线段是否相交
题目大意:给出n条线段,问是否存在一条直线,使得n条线段在直线上的投影有至少一个公共点. 题目思路:如果假设成立,那么作该直线的垂线l,该垂线l与所有线段相交,且交点可为线段中的某两个交点 证明:若有 ...
- The Rings Akhaten
在其他的平行宇宙中存在着一个古老的星系--Akhaten,星系中有七个世界,上面生活着Panbabylonian.Lucanian等物种,不过外界也常常把他们统称为Akhet,因为这七个世界环绕着同一 ...
- PHP 实现定时任务的几种方法
一. 简单直接不顾后果型 <?php ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执行. set_time_limit(0);// 通过set_time_limi ...
- Android根据Button状态(normal,focused,pressed)显示不同背景图片
Android根据Button状态(normal,focused,pressed)显示不同背景图片 Android中Button 有focused, selected, pressed 等不同状态,通 ...
- python解析XML之ElementTree
#coding=utf-8 from xml.etree import ElementTree as ET tree=ET.parse('test.xml') root = tree.getroot( ...
- 转:使用WebDriver过程中遇到的那些问题
在做web项目的自动化端到端测试时主要使用的是Selenium WebDriver来驱动浏览器.Selenium WebDriver的优点是支持的语言多,支持的浏览器多.主流的浏览器Chrome.Fi ...
- java项目中使用guava的工具包的心得
原文:http://www. zuidaima.com/blog/3182745969511424.htm 以前只是听过这个工具包,但是真正用的话还是在D75需求中.我要实现把前台传入的list集 ...
- 分享一款CSS框架
1.http://bulma.io/documentation/elements 2.支持IE9+ 3.内容:
- zf-关于收费统计没出来监利县的问题
这个问题一看就知道跟存储过程有关,所以我直接去后台实现类找到了这个的存储过程 存储过程里第一句就是quhua_code 从 select 开始 就是查询出 4个地方的名字 然后在把这查询出的数据给@ ...