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 ...
随机推荐
- Objective-C代码的文件扩展名与数据类型
Objective-C数据类型可以分为:基本数据类型.对象类型和id类型. 基本数据类型有:int.float.double和char类型. 对象类型就是类或协议所声明的指针类型,例如:SAutore ...
- 161128、Redis 4.0发布及其新功能介绍
Redis 4.0-rc1 发布了,这是 4.0 的首个 RC 版.Redis 是一个高性能的key-value数据库.Redis 的出现,很大程度补偿了memcached这类keyvalue存储的不 ...
- TM1680的I2C的51例程
搞到一个例程,虽然是51的, 但是我的ST版本也是用的模拟I2C, 分析一下吧: unsigned char i=0;TM1680start(); //I2C起始信号 TM1680SendByte( ...
- Linux之sed命令详解
简介 sed 是一种在线编辑器,它一次处理一行内容.处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的 ...
- memcache缓存的使用
今天在,本地测试了一个关于memcache的demo. 本地集成环境(wamp)环境如下:php 5.5.12 .Apache 2.4.9 .mysql 5.6.17 1.除了添加配置.添加php的 ...
- 判断listview是上滑还是下滑的方法
方法一: 用setOnScrollListener(new AbsListView.OnScrollListener())来实现,判断滑动后显示的第一个条目 ,与滑动前的第一个条目的大小来判断, 这种 ...
- 通过spring工厂读取property配置文件
/** * Created by ywq on 2016/6/30. */ @Named public class PropertyConfig { private static AbstractBe ...
- android应用程序中获取view 的位置
1. 相对位置: getLeft() , getRight(), getTop(), getBottom() 在Android中可以把left相当于X轴值, top相当于Y轴值, 通过这两个值Andr ...
- 周赛-Integration of Polynomial 分类: 比赛 2015-08-02 08:40 10人阅读 评论(0) 收藏
Integration of Polynomial Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/O ...
- 分页sql存储过程算法
/****** Object: StoredProcedure [dbo].[PRO_Pub_FenYe] Script Date: 08/04/2014 11:14:22 ******/ SET A ...