Minimum Transport Cost

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11017    Accepted Submission(s):
3058

Problem Description
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

a certain tax which will be charged whenever any cargo
passing through one city, except for the source and the destination
cities.

You must write a program to find the route which has the minimum
cost.

 
Input
First is N, number of cities. N = 0 indicates the end
of input.

The data of path cost, city tax, source and destination cities
are given in the input, which is of the form:

a11 a12 ... a1N
a21 a22
... a2N
...............
aN1 aN2 ... aNN
b1 b2 ... bN

c d
e
f
...
g h

where aij is the transport cost from city i to city j,
aij = -1 indicates there is no direct path between city i and city j. bi
represents the tax of passing through city i. And the cargo is to be delivered
from city c to city d, city e to city f, ..., and g = h = -1. You must output
the sequence of cities passed by and the total cost which is of the
form:

 
Output
From c to d :
Path:
c-->c1-->......-->ck-->d
Total cost :
......
......

From e to f :
Path:
e-->e1-->..........-->ek-->f
Total cost : ......

Note: if
there are more minimal paths, output the lexically smallest one. Print a blank
line after each test case.

 
Sample Input
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
 
Sample Output
From 1 to 3 :
Path: 1-->5-->4-->3
Total cost : 21

From 3 to 5 :
Path: 3-->4-->5
Total cost : 16

From 2 to 4 :
Path: 2-->1-->5-->4
Total cost : 17

 
Source
 disguss里给的某些数据根本就是错的吧。。我的错误一开始是变量写错结果对着他们的test改半天ccc。一直死循环
floyd不必多数,字典序得话,肯定有最前面的字母决定总体的大小,所以path[i][j]表示i-->j中间经过的第一个点
还有就是单向图这个我倒是没写错。

#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ql(a,b) memset(a,b,sizeof(a))
int e[105][105],b[105];
int path[105][105];
void floyd(int n)
{
int i,j,k;
for(k=1;k<=n;++k)
for(i=1;i<=n;++i)
for(j=1;j<=n;++j){
if(e[i][j]>b[k]+e[i][k]+e[k][j]){
e[i][j]=b[k]+e[i][k]+e[k][j];
path[i][j]=path[i][k];
}
else if(e[i][j]==b[k]+e[i][k]+e[k][j]&&path[i][j]>path[i][k]){
path[i][j]=path[i][k];
}
}
}
void print(int u,int v)
{
int k;
if(u==v)
{
printf("%d",v);
return ;
}
k=path[u][v];
printf("%d-->",u);
print(k,v);
}
int main()
{
int n,m,i,j,k,a,c,t=1;
while(cin>>n&&n){
for(i=1;i<=n;++i)
for(j=1;j<=n;++j){
scanf("%d",&e[i][j]);
if(e[i][j]==-1) e[i][j]=inf;
path[i][j]=j;
}
for(i=1;i<=n;++i) cin>>b[i];
floyd(n);
while(cin>>a>>c&&(a+1||c+1)){
printf("From %d to %d :\nPath: ",a,c);
print(a,c);
printf("\nTotal cost : %d\n\n",e[a][c]);
}
}
return 0;
}

 

hdu 1385 floyd字典序的更多相关文章

  1. hdu 1385 Floyd 输出路径

    Floyd 输出路径 Sample Input50 3 22 -1 43 0 5 -1 -122 5 0 9 20-1 -1 9 0 44 -1 20 4 05 17 8 3 1 //收费1 3 // ...

  2. hdu 1385 floyd记录路径

    可以用floyd 直接记录相应路径 太棒了! http://blog.csdn.net/ice_crazy/article/details/7785111 #include"stdio.h& ...

  3. hdu 5008 查找字典序第k小的子串

    Boring String Problem Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  4. hdu 1385 Minimum Transport Cost (floyd算法)

    貌似···················· 这个算法深的东西还是很不熟悉!继续学习!!!! ++++++++++++++++++++++++++++ ======================== ...

  5. hdu 1385 Minimum Transport Cost(floyd &amp;&amp; 记录路径)

    Minimum Transport Cost Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/O ...

  6. HDU 1385 Minimum Transport Cost( Floyd + 记录路径 )

    链接:传送门 题意:有 n 个城市,从城市 i 到城市 j 需要话费 Aij ,当穿越城市 i 的时候还需要话费额外的 Bi ( 起点终点两个城市不算穿越 ),给出 n × n 大小的城市关系图,-1 ...

  7. HDU 1385 Minimum Transport Cost (输出字典序最小路径)【最短路】

    <题目链接> 题目大意:给你一张图,有n个点,每个点都有需要缴的税,两个直接相连点之间的道路也有需要花费的费用.现在进行多次询问,给定起点和终点,输出给定起点和终点之间最少花费是多少,并且 ...

  8. hdu 1385 Minimum Transport Cost (Floyd)

    Minimum Transport CostTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

  9. HDU 1385 Minimum Transport Cost (Dijstra 最短路)

    Minimum Transport Cost http://acm.hdu.edu.cn/showproblem.php?pid=1385 Problem Description These are ...

随机推荐

  1. Visual Studio的“Waiting for a required operation to complete...”问题

    自从使用Visual Studio 2013之后,多次遇到这个恼人的“Waiting for a required operation to complete...”问题. 问题发生于在Visual ...

  2. nginx 下使用 bootstrap 字体的问题

    使用boostrap时,出现 glyphicons-halflings-regular.ttf glyphicons-halflings-regular.woff glyphicons-halflin ...

  3. 为什么 要弄清楚 mysql int(5) int(11) bigint 自建mysql主键id python random 科学计数法

    场景: 有1.2亿条问答数据,相同问题的不同答案为不同条的数据,且该表数据逐日递增: 第三方需求(不合理): 将问题.答案数据分别放入问题表.答案表: 问题表的主键为整数,在答案表中,每行数据有相应的 ...

  4. Python开发【Django】:图片验证码、KindEditor

    图片验证码 生成图片验证码需要以下: session check_code.py(依赖:Pillow,字体文件) 模块安装 pip install Pillow src属性后面加? 在utils下拷贝 ...

  5. 《Java程序猿面试笔试宝典》之Java程序初始化的顺序是如何的

    在Java语言中.当实例化对象时.对象所在类的全部成员变量首先要进行初始化,仅仅有当全部类成员完毕初始化后,才会调用对象所在类的构造函数创建对象.    Java程序的初始化一般遵循以下三个原则(以下 ...

  6. java-基础-【四】实际编程中的对象

    一.概述 实际编程开发中,仅仅一个数据库对象映射是满足不了各种复杂需求. O/R Mapping 是 Object Relational Mapping(对象关系映射)的缩写.通俗点讲,就是将对象与关 ...

  7. SLAM FOR DUMMIES 第5-8章 中文翻译

    5,SLAM的处理过程 SLAM过程包括许多步骤,该过程的目标是使用环境更新机器人的位置.由于机器人的里程计通常是存在误差的,我们不能直接依赖于里程计.我们可以用激光扫描环境来校正机器人的位置,这是通 ...

  8. zcash 的资料

    我的比特币使用的是 electrum 2.9.3 版本.我的zcash用的是 jaxx 1.2 版. zcash又叫zec,可以在 bithumb (韩国的) 平台上进行交易zcash. zcash ...

  9. PAT 1062 Talent and Virtue[难]

    1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...

  10. python学习之路-day8

    一.接口与归一化设计 1.什么是接口 调用某个功能的方法/方式/入口 2.为什么要用接口 接口提取了一群类共同的函数,可以把接口当做一个函数的集合. 然后让子类去实现接口中的函数. 这么做的意义在于归 ...