POJ 1122 FDNY to the Rescue! Floyd 打印路径就行了
题目大意:
纽约消防部门的支援速度是值得纽约人骄傲的一件事。但是他们想要最快的支援速度,帮助他们提升支援速度他们要调度离着火点最近的一个消防站。他们要你写一个程序来维护纽约消防站的光荣传统。软件需要有的功能是,能获取着火点的地址 和 消防站的位置, 街道交叉路口, 从一个交叉路口到达另一个交叉路口的时间。 他将要计算从消防站到达着火点需要多少时间。
给你一个具体的着火点的地址,这个软件应该找出所有消防站到达着火点的距离, 并且从小到大进行排序。以便消防员来调度人员到达救火地点。
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
using namespace std;
#define INF 0xfffffff
#define maxn 40 struct Point
{
int e, w;
} dist[maxn]; bool cmp(Point A,Point B)
{
return A.w < B.w;
}
int Path[maxn][maxn], G[maxn][maxn], n; void Floyd()
{
for(int k=; k<=n; k++)
{
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
if(G[i][j] > G[i][k] + G[k][j] )
{
G[i][j] = G[i][k] + G[k][j];
Path[i][j] = Path[i][k];
}
}
}
}
} void PutPath(int Star,int End)
{
while(Star != End)
{
printf("\t%d", Star);
Star = Path[Star][End];
}
printf("\t%d\n", Star);
} int main()
{
int a; cin >> n; for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
Path[i][j] = j;
cin >> G[i][j]; if(G[i][j] == -)
G[i][j] = INF;
}
}
int End, k = ; Floyd(); cin >> End; while(scanf("%d",&a) != EOF)
{
dist[k].w = G[a][End];
dist[k++].e = a;
} sort(dist, dist + k, cmp); cout << "Org\tDest\tTime\tPath" << endl; for(int i=; i<k; i++)
{
printf("%d\t%d\t%d", dist[i].e, End, G[dist[i].e][End]); PutPath(dist[i].e, End);
}
return ;
}
POJ 1122 FDNY to the Rescue! Floyd 打印路径就行了的更多相关文章
- POJ 1122.FDNY to the Rescue! Dijkstra
FDNY to the Rescue! Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2808 Accepted: 86 ...
- POJ 1122 FDNY to the Rescue!(最短路+路径输出)
http://poj.org/problem?id=1122 题意:给出地图并且给出终点和多个起点,输出从各个起点到终点的路径和时间. 思路: 因为有多个起点,所以这里反向建图,这样就相当于把终点变成 ...
- POJ 1122 FDNY to the Rescue!
给出某些交叉点的距离,-1 表示无法到达. 然后给出火灾发生点 和 附近的消防局位置. 排列消防局 的 时间 与路径. 反向建图,以火灾出发点为起点做一次SPFA. #include<cstd ...
- poj 3216 Repairing Company(最短路Floyd + 最小路径覆盖 + 构图)
http://poj.org/problem?id=3216 Repairing Company Time Limit: 1000MS Memory Limit: 131072K Total Su ...
- 关于floyd 打印路径的问题
我们令 f[i][j] 表示从 i-->j的最短路上j前面的那个点. 显然初始化时 f[i][j]=i; (这样的话先判断一下i是否能到达j好点) 更新条件时,当发现通过点k能使最短 ...
- POJ 1141 Brackets Sequence(区间DP, DP打印路径)
Description We give the following inductive definition of a “regular brackets” sequence: the empty s ...
- poj1122 FDNY to the Rescue!(dij+反向建图+输出路径)
题目链接:poj1122 FDNY to the Rescue! 题意:给出矩阵,矩阵中每个元素tij表示从第i个交叉路口到第j个交叉路口所需时间,若tij为-1则表示两交叉路口之间没有直接路径,再给 ...
- SPFA和FLOYD算法如何打印路径
早晨碰到了一题挺裸的最短路问题需要打印路径:vijos1635 1.首先说说spfa的方法: 其实自己之前打的最多的spfa是在网格上的那种,也就是二维的 一维的需要邻接表+queue 以及对于que ...
- poj 2965 The Pilots Brothers' refrigerator(dfs 枚举 +打印路径)
链接:poj 2965 题意:给定一个4*4矩阵状态,代表门的16个把手.'+'代表关,'-'代表开.当16个把手都为开(即'-')时.门才干打开,问至少要几步门才干打开 改变状态规则:选定16个把手 ...
随机推荐
- [Falcor] Indroduce to Model
How to work with JSON data indirectly through a Falcor Model. The Falcor Model allows you to work wi ...
- htaccess 正则规则整理(转)
为了方便 htaccess 编写正则,这里整理了一下 htaccess 的正则规则. # —— 位于行首时表示注释. [F] —— Forbidden(禁止): 命令服务器返回 403 Forbidd ...
- PHP 函数的“引用返回”概念释疑(转)
很多时候我们会看到这样的代码(出自 CI 框架源码): 1 $class =& load_class('a','b'); 我们都知道其中的'&'是指引用,但是它的作用是什么呢?它能够解 ...
- Java 下实现锁无关数据结构--转载
介绍 通常在一个多线程环境下,我们需要共享某些数据,但为了避免竞争条件引致数据出现不一致的情况,某些代码段需要变成原子操作去执行.这时,我们便需要利用各种同步机制如互斥(Mutex)去为这些代码段加锁 ...
- Swift的闭包(一):闭包简介、闭包表达式的优化
定义:Closures are self-contained blocks of functionality that can be passed around and used in your co ...
- Codeforces Round #291 (Div. 2) C - Watto and Mechanism 字符串
[题意]给n个字符串组成的集合,然后有m个询问(0 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) ,每个询问都给出一个字符串s,问集合中是否存在一个字符串t,使得s和t长度相同,并且仅有一个 ...
- 循序渐近学docker---笔记
1.安装docker 环境:ubuntu 16.04 sudo apt-get install docker.io root@ld-Lenovo-G470:~# docker -vDocker ver ...
- oracle 的变量的定义和赋值
第一种 :先定义后赋值 代码 : declare V_AgeingType varchar2(500); begin V_AgeingType :='111'; end 第二种 ...
- 条件注释判断浏览器版本<!--[if lt IE 9]>(转载)
<!--[if !IE]><!--> 除IE外都可识别 <!--<![endif]--> <!--[if IE]> 所有的IE可识别 <![ ...
- Js数学函数1
1.取模求余数 //1.JS取模求余 //输出 for (var i = 0; i < 20; i++) { if (i % 3 == 0) { documentHelper.WriteText ...