【HDOJ】1385 Minimum Transport Cost
Floyd。注意字典序!!!
#include <stdio.h>
#include <string.h> #define MAXNUM 55
#define INF 0x1fffffff int cost[MAXNUM][MAXNUM];
int path[MAXNUM][MAXNUM];
int taxes[MAXNUM];
int que[MAXNUM];
int n; void floyd(int n) {
int i, j, k, tmp; for (i=; i<=n; ++i)
for (j=; j<=n; ++j)
path[i][j] = j; for (k=; k<=n; ++k) {
for (i=; i<=n; ++i) {
for (j=; j<=n; ++j) {
tmp = cost[i][k]+cost[k][j]+taxes[k];
if (cost[i][j] > tmp) {
cost[i][j] = tmp;
path[i][j] = path[i][k];
} else if (cost[i][j] == tmp) {
if (path[i][j] > path[i][k])
path[i][j] = path[i][k];
}
}
}
}
} void output(int a, int b) {
int front, rear;
int x = a;
front = rear = ; //que[rear++] = a;
while (path[x][b] != b) {
que[rear++] = path[x][b];
x = path[x][b];
}
if (a != b)
que[rear++] = b; printf("From %d to %d :\n", a, b);
printf("Path: %d", a);
while (front < rear)
printf("-->%d", que[front++]);
printf("\nTotal cost : %d\n\n", cost[a][b]);
} int main() {
int a, b;
int i, j; while (scanf("%d", &n)!=EOF && n) {
for (i=; i<=n; ++i)
for (j=; j<=n; ++j) {
scanf("%d", &cost[i][j]);
if (cost[i][j] < )
cost[i][j] = INF;
}
for (i=; i<=n; ++i)
scanf("%d", &taxes[i]);
floyd(n);
while () {
scanf("%d %d", &a, &b);
if (a==- && b==-)
break;
output(a, b);
}
} return ;
}
【HDOJ】1385 Minimum Transport Cost的更多相关文章
- 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 && 记录路径)
Minimum Transport Cost Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- hdu 1385 Minimum Transport Cost (Floyd)
Minimum Transport CostTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- HDU 1385 Minimum Transport Cost (输出字典序最小路径)【最短路】
<题目链接> 题目大意:给你一张图,有n个点,每个点都有需要缴的税,两个直接相连点之间的道路也有需要花费的费用.现在进行多次询问,给定起点和终点,输出给定起点和终点之间最少花费是多少,并且 ...
- hdu 1385 Minimum Transport Cost (floyd算法)
貌似···················· 这个算法深的东西还是很不熟悉!继续学习!!!! ++++++++++++++++++++++++++++ ======================== ...
- 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个城市,一些城市之间会有一些道路,有边权.并且每个城市都会有一些费用. 然后你一些起点和终点,问你从起点到终点最少需要多少路途. 除了起点和终点,最短路的图中的每个城市的费用都要加上. 思 ...
- 【HDOJ】3473 Minimum Sum
划分树解.主席树解MLE. /* 3473 */ #include <iostream> #include <sstream> #include <string> ...
- HDU 1385 Minimum Transport Cost 最短路径题解
本题就是使用Floyd算法求全部路径的最短路径,并且须要保存路径,并且更进一步须要依照字典顺序输出结果. 还是有一定难度的. Floyd有一种非常巧妙的记录数据的方法,大多都是使用这种方法记录数据的. ...
随机推荐
- Linux终端Ctrl相关快捷键
快速跳至行首:Ctrl+A 快速跳至行尾:Ctrl+E 向前删除至行首:Ctrl+U 向后删除至行尾:Ctrl+K 向后删一个单词:Ctrl+D 清屏:Crtl+L(clear)
- ORA-00928: 缺失 SELECT 关键字
ORA-00928: 缺失 SELECT 关键字 一般是表的列名使用了关键字,解决办法就是加双引号 来自为知笔记(Wiz)
- PHP 正则通配符
$a = preg_match('/ph+p/','aaaphpbbbp'); +的前导就是h $a = preg_match('/ph+p/','aaaphhhhhhhhhhpbbbp'); //第 ...
- tomcat上servlet程序的配置与处理servlet请求过程
手动配置: tomcat服务器下web项目的基本目录结构 |-tomcat根目录 |-webapps |-WebRoot : web应用的根目录 |-静态资源(html+css+js+image+ve ...
- Java8 map和reduce
map final List<Integer> numbers = Arrays.asList(1, 2, 3, 4); final List<Integer> doubleN ...
- 百练_2409 Let it Bead(Polya定理)
描述 "Let it Bead" company is located upstairs at 700 Cannery Row in Monterey, CA. As you ca ...
- C/C++之Exercise
一.C/C++之初学Demo---C++调用C.h文件使用实例: 工程结构: exercise.h code: #ifndef _EXERCISE_H_ #define _EXERCISE_H_ #i ...
- eclipse下使用Genymotion调试Android程序出现的问题
一. The connection to adb is down, and a severe error has occured. You must restart adb and Eclipse. ...
- .net中String是引用类型还是值类型 以及 C#深层拷贝浅层拷贝
http://www.cnblogs.com/yank/archive/2011/10/24/2204145.html http://www.cnblogs.com/zwq194/archive/20 ...
- js 默认的参数、可变的参数、变量作用域
可以通过arguments对象来实现可变的参数 在函数代码中,使用特殊对象 arguments,开发者无需明确指出参数名,就能访问它们. arguments是一个数组对象,可以通过下标来实别参数的位置 ...