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 ...
随机推荐
- 广播发送者&广播接收者介绍
1.广播接收者 广播接收者简单地说就是接收广播意图的Java类,此Java类继承BroadcastReceiver类,重写: public void onReceive(Context context ...
- Android扫描文件
扫描文件及文件夹 package com.bwie.demo; import java.io.File; import java.io.FileFilter; import java.util.Arr ...
- webssh software
shellinabox是由Markus Gutschke开发的一款自由开源的基于Web的Ajax的终端模拟器.它使用AJAX技术,通过Web浏览器提供了类似原生的 Shell 的外观和感受. yum ...
- Java局部变量final
局部变量和形参带final. 在一个线程A中开起另一个线程B,如果线程B要使用线程A的局部变量,那么A的局部变量需要定义成final.理由:局部变量是线程内部共享的,每一个线程内的不能访问其他线程的局 ...
- 给windows服务打包,并生成安装程序
一. 添加新建项目-->安装部署-->安装项目 二.安装程序上-->右键视图-->文件系统-->应用程序文件夹-->右键-->添加项目输出 选择做好的wind ...
- ecshop微信支付(0923更新)商户支付密钥key的生成与设置
ECSHOP 微信支付(0923更新)商户支付密钥key的生成与设置 说明:新版微信支付,用户必须授权登录才能支付.需要商家自己设置商户号支付密钥. 申请微信支付手机版部分时需要填写的配置接口地址: ...
- 还原数据库,恢复SQLSERVER登录名的问题
还原SQLSERVER数据库,原来的数据库的于当前SQLSERVER同名用户就不能再登录了,原因是当前SQLSERVERD的master数据库的sysxlogins表的的sid与还原后的数据库的sys ...
- Cocos2dx框架常用单词(一)
收集了一些Cocos2dx里面主要单词的翻译. Toggle:切换Finite:有限Instant:瞬时interval:间隔Flip:翻转place:座位,放置Target:目标reverse:反向 ...
- Monthly Expense(二分查找)
Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17982 Accepted: 7190 Desc ...
- SIGPIPE信号详解
转自:http://blog.csdn.net/lmh12506/article/details/8457772 前一段面试的时候被问到项目中有没有处理SIGPIPE信号,怎么处理的?当时没有答出来, ...