poj 1502 最短路+坑爹题意
链接:http://poj.org/problem?id=1502
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 5249 | Accepted: 3237 |
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.''
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 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
题意怎么会这个样子?根本读不出来这个意思,是要有多坑???
看了别人的博客,原来是求什么从1号点到其他各点的最小距离的最大值
还看不懂?
1--->2 35
1--->3 30
1--->4 20
1--->5 10 所以就是35…………
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define INF 1000000000
#define MAXX 105 int map[MAXX][MAXX];
int d[MAXX],visit[MAXX]; void Dijkstra(int n)
{
int i,j;
memset(visit,,sizeof(visit));
for(i=;i<=n;i++)
{
d[i] = (i==? : INF);
}
for(i=;i<=n;i++)
{
int x,m=INF;
for(j=;j<=n;j++)
{
if(!visit[j] && d[j]<=m)
{
m = d[x = j];
}
}
visit[x]=;
for(j=;j<=n;j++)
{
if(!visit[j] && d[j]>d[x]+map[x][j])
{
d[j]=d[x]+map[x][j];
}
}
}
} int main()
{
int n,i,j;
char m[];
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); while(scanf("%d",&n)!=EOF)
{
for(i=;i<MAXX;i++)
for(j=;j<MAXX;j++)
{
if(i == j)
{
map[i][j]=;
}
else
map[i][j]=INF;
}
for(i=;i<=n;i++)
{
for(j=;j<i;j++)
{
scanf("%s",m);
if(m[] != 'x')
{
map[i][j]=map[j][i]=atoi(m);//printf("%d##",atoi(m));
}
}
}
Dijkstra(n);
int maxx=;
for(i=;i<=n;i++)
{
if(maxx<d[i])
maxx=d[i];
}
printf("%d\n",maxx);
}
return ;
}
poj 1502 最短路+坑爹题意的更多相关文章
- Heavy Transportation POJ 1797 最短路变形
Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你 ...
- 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 MaeIstrom ( 裸最短路 || atoi系统函数 )
题意 : 给出 N 个点,各个点之间的路径长度用给出的下三角矩阵表示,上上角矩阵和下三角矩阵是一样的,主对角线的元素都是 0 代表自己到达自己不用花费,现在问你从 1 到 N 的最短路,矩阵的 x 代 ...
- POJ 1502 MPI Maelstrom (最短路)
MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6044 Accepted: 3761 Des ...
- 【单源最短路】dijstra poj 1502
#include <cstdio> #include <iostream> #include <stdlib.h> #include <memory.h> ...
- POJ 1502 MPI Maelstrom [最短路 Dijkstra]
传送门 MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5711 Accepted: 3552 ...
- poj 1847 最短路简单题,dijkstra
1.poj 1847 Tram 最短路 2.总结:用dijkstra做的,算出a到其它各个点要改向的次数.其它应该也可以. 题意: 有点难懂.n个结点,每个点可通向ki个相邻点,默认指向第一个 ...
- POJ 1502 MPI Maelstrom (Dijkstra)
题目链接:http://poj.org/problem?id=1502 题意是给你n个点,然后是以下三角的形式输入i j以及权值,x就不算 #include <iostream> #inc ...
随机推荐
- DButil
纲要: Properties prop = new Properties(); BasicDataSource ds = new BasicDataSorce(); Connection conn = ...
- SpringMVC @RequestBody接收Json对象字符串 demo
springmvc 的这个 @RequestBody 用得比较少,今天看了一下,还是很方便. @RequestBody 接收类似 [{name: "test"}, {name: & ...
- grid
- export
export export PATH=$PATH:/ROOT
- struts2结果类型
struts2结果类型: 结果类型 描述 前request域属性是否丢失 1 dispatcher 用于与jsp整合的结果类型.默认结果类型. 2 chain Action链式处理结果类型.前一个Ac ...
- php开启openssl的方法
windows下开启方法: 1: 首先检查php.ini中:extension=php_openssl.dll是否存在, 如果存在的话去掉前面的注释符‘:’, 如果不存在这行,那么添加extensio ...
- MyEclipse+Android 安装配置
1.先安装M有Eclipse 就是不断点:下一步下一步最后finish 激活:http://blog.my-eclipse.cn/myeclipse-2014-crack.html (该网站上 ...
- vnc里鼠标拖动终端就会产生ctrl+c终端
然后把有道词典给关了就好了...
- [转]iOS应用程序生命周期(前后台切换,应用的各种状态)详解
转载地址:http://blog.csdn.net/totogo2010/article/details/8048652 iOS的应用程序的生命周期,还有程序是运行在前台还是后台,应用程序各个状态的变 ...
- Present
Present time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...