hdu 1385 Minimum Transport Cost (Floyd)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12860 Accepted Submission(s): 3633
These are N cities in Spring country. Between each pair of cities there may be one transportation track or none. Now there is some cargo that should be delivered from one city to another. The transportation fee consists of two parts:
The cost of the transportation on the path between these cities, and
First is N, number of cities. N = 0 indicates the end of input.
a21 a22 ... a2N
...............
aN1 aN2 ... aNN
b1 b2 ... bN
e f
...
g h
From c to d :
Path: c-->c1-->......-->ck-->d
Total cost : ......
......
Path: e-->e1-->..........-->ek-->f
Total cost : ......
5
0 3 22 -1 4
3 0 5 -1 -1
22 5 0 9 20
-1 -1 9 0 4
4 -1 20 4 0
5 17 8 3 1
1 3
3 5
2 4
-1 -1
0
From 1 to 3 :
Path: 1-->5-->4-->3
Total cost : 21
Path: 3-->4-->5
Total cost : 16
Path: 2-->1-->5-->4
Total cost : 17
C/C++:
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdio>
#include <climits>
#include <algorithm>
#define INF 0xffffff
using namespace std; int n, my_map[][], my_tax[], my_begin, my_end, my_path[][]; void my_floyd()
{
for (int i = ; i <= n; ++ i)
for (int j = ; j <= n; ++ j)
my_path[i][j] = j;
for (int k = ; k <= n; ++ k)
for (int i = ; i <= n; ++ i)
for (int j = ; j <= n; ++ j)
{
int my_temp = my_map[i][k] + my_map[k][j] + my_tax[k];
if (my_temp < my_map[i][j])
{
my_map[i][j] = my_temp;
my_path[i][j] = my_path[i][k];
}
else if (my_temp == my_map[i][j] && my_path[i][j] > my_path[i][k])
my_path[i][j] = my_path[i][k];
}
} int main()
{
while (~scanf("%d", &n), n)
{
for (int i = ; i <= n; ++ i)
for (int j = ; j <= n; ++ j)
{
int my_temp;
scanf("%d", &my_temp);
if (my_temp == -)
my_map[i][j] = INF;
else
my_map[i][j] = my_temp;
}
for (int i = ; i <= n; ++ i)
scanf("%d", &my_tax[i]);
my_floyd();
while (scanf("%d%d", &my_begin, &my_end), my_begin != - || my_end != -)
{
printf("From %d to %d :\n", my_begin, my_end);
printf("Path: %d", my_begin);
int my_now = my_begin;
while (my_now != my_end)
{
printf("-->%d", my_path[my_now][my_end]);
my_now = my_path[my_now][my_end];
}
printf("\nTotal cost : %d\n\n", my_map[my_begin][my_end]);
}
}
return ;
}
hdu 1385 Minimum Transport Cost (Floyd)的更多相关文章
- hdu 1385 Minimum Transport Cost(floyd && 记录路径)
Minimum Transport Cost Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- HDU 1385 Minimum Transport Cost (Dijstra 最短路)
Minimum Transport Cost http://acm.hdu.edu.cn/showproblem.php?pid=1385 Problem Description These are ...
- hdu 1385 Minimum Transport Cost (floyd算法)
貌似···················· 这个算法深的东西还是很不熟悉!继续学习!!!! ++++++++++++++++++++++++++++ ======================== ...
- HDU 1385 Minimum Transport Cost( Floyd + 记录路径 )
链接:传送门 题意:有 n 个城市,从城市 i 到城市 j 需要话费 Aij ,当穿越城市 i 的时候还需要话费额外的 Bi ( 起点终点两个城市不算穿越 ),给出 n × n 大小的城市关系图,-1 ...
- hdu 1385 Minimum Transport Cost
http://acm.hdu.edu.cn/showproblem.php?pid=1385 #include <cstdio> #include <cstring> #inc ...
- HDU 1385 Minimum Transport Cost (最短路,并输出路径)
题意:给你n个城市,一些城市之间会有一些道路,有边权.并且每个城市都会有一些费用. 然后你一些起点和终点,问你从起点到终点最少需要多少路途. 除了起点和终点,最短路的图中的每个城市的费用都要加上. 思 ...
- HDU 1385 Minimum Transport Cost 最短路径题解
本题就是使用Floyd算法求全部路径的最短路径,并且须要保存路径,并且更进一步须要依照字典顺序输出结果. 还是有一定难度的. Floyd有一种非常巧妙的记录数据的方法,大多都是使用这种方法记录数据的. ...
- HDU 1385 Minimum Transport Cost (输出字典序最小路径)【最短路】
<题目链接> 题目大意:给你一张图,有n个点,每个点都有需要缴的税,两个直接相连点之间的道路也有需要花费的费用.现在进行多次询问,给定起点和终点,输出给定起点和终点之间最少花费是多少,并且 ...
- Minimum Transport Cost(floyd+二维数组记录路径)
Minimum Transport Cost Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
随机推荐
- css 文字间距
letter-spacing : 字与字之间的距离 text-indent : 行的抬头间距 line-height : 行高度
- opencv::图像矩(Image Moments)
矩的概念介绍 1.几何矩 2.中心距 3.中心归一化距 4.图像中心Center(x0, y0) 计算矩 moments( InputArray array, // 输入数据 bool binaryI ...
- 概念理解-异步IO
#include <aio.h> /* 函数名 :int aio_write(struct aiocb *aiocbp) 参 数 :struct aiocb *aiocbp 返回值 :执行 ...
- ajax 轮询(适合web端二维码请求)
(前几天 一直弄二维码轮询登录 想了半天 总算弄出来了 分享给大家 ^-^) 轮询: 所谓轮询 肯定需要 setInterval 但是怎么加ajax请求 需要有点小问题而且轮询成功后需要停 ...
- shell变量(二)
变量名的命名规范: 1.命名只能使用英文字母.数字和下划线,且不能以数字开头: 2.不能存在空格‘: 3.不能使用标点符号: 4.不能使用bash里的关键字(可使用help命令查看保留关键字) 变量的 ...
- 四jmeter脚本开发
4.1工作区介绍 4.2http协议录制 a.使用badboy进行录制(目前公司测试系统使用badboy界面不友好,暂时不用,之后再补充) b.jmeter代理服务器进行录制 (1)浏览器代理配置(以 ...
- Sentinel Getting Started And Integration of Spring Cloud Alibaba Tutorials
原文链接:Sentinel Getting Started And Integration of Spring Cloud Alibaba Tutorials Sentinel Getting Sta ...
- Java Stream函数式编程图文详解(二):管道数据处理
一.Java Stream管道数据处理操作 在本号之前发布的文章<Java Stream函数式编程?用过都说好,案例图文详解送给你>中,笔者对Java Stream的介绍以及简单的使用方法 ...
- 计算机基础之编程 + 基本组成 + 组成补充 + 操作系统(day01整理)
目录 一 计算机基础之编程 (一) 什么是编程语言 (二) 什么是编程 (三) 为什么要编程 二 计算机的基本组成 (一) CPU(大脑) (1) 控制器 (2) 运算器 (二) 存储器(记忆) (1 ...
- Spark集群安装与配置
一.Scala安装 1.https://www.scala-lang.org/download/2.11.12.html下载并复制到/home/jun下解压 [jun@master ~]$ cd sc ...