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 ...
随机推荐
- 《FFT家族—从不会到崩溃(坑)》读blog笔记
免责声明 原文地址https://blog.csdn.net/linjiayang2016/article/details/80341958,作者linjiayang2016.\text{linjia ...
- [牛客网NOIP赛前集训营-普及组(第二场)]D-合法括号序列
链接:https://www.nowcoder.com/acm/contest/165/D来源:牛客网 合法括号序列 键盘上有左括号(,右括号),和退格键-,共三个键. 牛牛希望按键n次,使得输入的字 ...
- Centos7安装moloch步骤
Centos7安装moloch步骤 Moloch 是一个由AOL开源的,能够大规模的捕获IPv4数据包(PCAP).索引和数据库系统,由以下三个部分组成: capture :绑定interface ...
- Vue学习系列(三)——基本指令
前言 在上一篇中,我们已经对组件有了更加进一步的认识,从组件的创建构造器到组件的组成,进而到组件的使用,.从组件的基本使用.组件属性,以及自定义事件实现父子通讯和巧妙运用插槽slot分发内容,进一步的 ...
- 基础安全术语科普(六)——exploit
exploit (漏洞利用) 利用漏洞存在两种攻击形式: 1.Remote(远程):利用系统漏洞来获得访问权限. 2.local(本地):需要对系统进行物理访问来实现攻击. 如何发现漏洞? 利用逆向工 ...
- Swagger -- 解决日期不正确
继 Swagger--解决日期格式显示为Unix时间戳格式 UTC格式 这篇博客解决的日期格式后又发现了一个问题 问题 查询出来的时间没有注意到足足少了8个小时,如图 解决 其实这个问题不是Swag ...
- Object 对象方法学习之(1)—— 使用 Object.assign 复制对象、合并对象
作用 Object.assign() 方法用于把一个或多个源对象的可枚举属性值复制到目标对象中,返回值为目标对象. 语法 Object.assign(target, ...sources) 参数 ta ...
- C/C++语言误区void main( )
很多人甚至市面上的一些书籍,都使用了void main( ) ,其实这是错误的.C/C++ 中从来没有定义过void main( ) .C++ 之父 Bjarne Stroustrup 在他的主页上的 ...
- numpy+pandas+ matplotlib模块(day18)
目录 numpy模块 二维数组 numpy数组的属性 T 数组的装置 dtype 数组元素的数据类型 size 数组元素的个数 ndim 数组的维数 shape数组的维度大小 astype 类型转换 ...
- PowerBI开发 第十五篇:Power BI的行级安全
Power BI支持行级安全(Row-Level Security,RLS)的权限控制,用于限制用户对Dashboard.报表和DataSet的访问.用户浏览的报表是相同的,但是看到的数据却是不同的. ...