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 ...
随机推荐
- sql 循环语句几种方式
--第一 declare @orderNum varchar(255) create table #ttableName(id int identity(1,1),Orders varchar(2 ...
- 内存泄露:*.hprof
使用Memory Analyzer tool(MAT)分析内存泄漏 转账地址:http://www.blogjava.net/rosen/archive/2010/06/13/323522.html ...
- 22、JSON/jQuery上
1)掌握JSON及其应用 2)了解jQuery的背景和特点 3)理解js对象和jQuery对象的区别 4)掌握jQuery九类选择器及应用(上) 声明:今天服务端我们使用Struts2技术 一 ...
- C#:控制WinForm界面的显示
控制WinForm界面在屏幕的四个角落显示,具体代码中有说明: using System; using System.Collections.Generic; using System.Drawing ...
- java面试每日一题12
题目:打印出如下图案(菱形) * *** ****** ******** ****** *** * public class Diamond { public static ...
- AngularJS 实现的输入自动完成补充功能
1.首先需要引入:angucomplete.js第三方库 2.增加model : var app = angular.module('app', ["angucomplete"]) ...
- 会话标识未更新(AppScan扫描结果)
最近工作要求解决下web的项目的漏洞问题,扫描漏洞是用的AppScan工具,其中此篇文章是关于会话标识未更新问题的.下面就把这块东西分享出来. 原创文章,转载请注明 ----------------- ...
- CSU 1325: A very hard problem 中南月赛的一道题。
1325: A very hard problem Time Limit: 3 Sec Memory Limit: 160 MBSubmit: 203 Solved: 53[Submit][Sta ...
- 湘潭 A simple problem
A simple problem Accepted : 30 Submit : 303 Time Limit : 15000 MS Memory Limit : 655360 KB Probl ...
- Android内存Activity泄露:Threads
Android编程中一个共同的困难就是协调Activity的生命周期和长时间运行的任务(task),并且要避免可能的内存泄露.思考下面Activity的代码,在它启动的时候开启一个线程并循环执行任务. ...