hdu 1385 Minimum Transport Cost Floyd

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情

In this problem,First I use dijkstra to solve it.But WA defeated me.I finally use Flyod.

The portal:http://acm.hdu.edu.cn/showproblem.php?pid=1385

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAXN 1005
const int INF = 0x3f3f3f3f;

int cost[MAXN][MAXN];
int route[MAXN][MAXN];
int power[MAXN];

void Input(){
	int n;
	while(scanf("%d",&n),n){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				scanf("%d",cost[i]+j);
				if(cost[i][j]==-1){
					cost[i][j] = INF;				
				}
				route[i][j] = j;	
			}			
		}
		for(int i=1;i<=n;i++){
			scanf("%d",power+i);			
		}
		for(int k=1;k<=n;k++){
			for(int i=1;i<=n;i++){
				for(int j=1;j<=n;j++){
					int temp = cost[i][k] + cost[k][j] + power[k] ;	
					if(temp < cost[i][j]){
						cost[i][j] = temp;
						route[i][j] = route[i][k];					
					}				
					else if(temp == cost[i][j]){
						if(route[i][j] > route[i][k]){
							route[i][j] = route[i][k];						
						}					
					}
				}
			}				
		}
		int g,h;
		while(scanf("%d %d",&g,&h),g+h+2){
	        printf("From %d to %d :\n",g,h);  
            printf("Path: %d",g);  
            int temp=g;  
            while(temp!=h)  
            {  
                printf("-->%d",route[temp][h]);  
                temp=route[temp][h];  
            }  
            printf("\n");  
            printf("Total cost : %d\n\n",cost[g][h]);   	
		}
	}
}

int main(){
	//freopen("a.in","r",stdin);
	Input();
	return 0;
}



hdu 1385 Minimum Transport Costfloyd 点击打开链接 floyd 。 现场写的死活过不去,后来看了看题解,和我的的还是有区别。 区别在,他正着记录路径。我逆着记录路径。。 结果我就错了/!!!!! 我擦简直了,我这样记录应该是没问题的呀。 思路:  就是跑一边floyd   更新的时候考虑如过到达一点其他路径如果前驱字典序小,就换。 然后 打印路径就好。 ac代码: #include usi 阅读详情

相关推荐

HDU 1385Minimum Transport Costfloyd+记录路径)

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1385 这题第一次是用s

scf0920 906

HDU - 1385 Minimum Transport Cost (floyd)

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 transpo...

hpu风之旅 208

HDU1385 Minimum Transport CostFloyd】+【路径记录】

Minimum Transport Cost Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7496    Accepted Submission(s): 1918 Problem Description The

长风的专栏 825

hdu 1385 Minimum Transport Cost (Floyd)

Minimum Transport CostTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12860 Accepted Submission(s): 3633 Problem DescriptionThese are N...

devon2014的博客 164

HDU - 1385 Minimum Transport CostFloyd

题意:已知一邻接矩阵,g[i][j]表示从 i 城道 j 城所需要的花费,b[ i ] 是从 i 城市路过(不是起始城市,也不是终点城市)要交的税。接着有若干询问,给出起点城市和终点城市,问少花费,并输出该路径,如果有多条短路径,输出字典序小的。后输出小花费。 思路:Floyd求a->b短路,长度相等时比较字典序,re[i][j] = k 表示从 i 到 j 是 i 先到 k ...

skyline的分享专栏 189

HDU - 1385 Minimum Transport Costfloyd打印路径

C - Minimum Transport Cost 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 de

于心有愧丶 448

HDU 1385 Minimum Transport CostFloyd + 路径输出)

Problem DescriptionThese 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 an...

←_← 250

floyd存字典序路径】【HDU1385】【Minimum Transport Cost

题目大意 求多组i到j的短路径 并输出字典序小.... 现在只会floyd的方式 利用dis[i][j] 表示i到j的路径中i 后面的节点 更新是比较dis[i][j] dis[i][k]. 记住这个就好 ,其余存法貌似会有问题。代码如下: #include #include #include #include #include #include

学习之路 566

HDU 1385 Minimum Transport CostFloyd算法 + 路径输出)

/** * Floyd + 路径输出 : * 挺裸的一题求两顶点多路。 除了要注意当路径有多条具有相同短路径的时候, * 按字典序输出。。 * 这题挺坑的: 首先数据坑,题目也没说明。 当询问的是a到a本身的话 * 是输出 Path: a 还是Path: a-->a (正确答案应该是前者) * 思路: 呃。。。上来直接Floyd吧。。 *

xuruoxin的专栏 2653

hdu 1385 Minimum Transport Cost(记录路径的floyd

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 a...

Vicente的博客 170

hdu 1385 Minimum Transport CostFloyd打印路径)

Minimum Transport Cost Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9113    Accepted Submission(s): 2406 Problem Description

Where amazing happens 452

HDU1385Minimum Transport Cost--Floyd

水题。。Floyd短路,开个path数组记录路径就好了。。 Minimum Transport Cost Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6019    Accepted Submission(s): 152

crazy_石头的专栏 751

HDU 1385Minimum Transport CostFloyd

Minimum Transport Cost Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8793    Accepted Submission(s): 2310 Problem Description These a

所谓梦想,就是永不停息的疯狂。。。。。 724

HDU1385 Minimum Transport Cost Floyd算法

题目大意:n个城市(编号1到n),有一批货物需要从a城市运到b城市已知城市之间道路是交通费(和城市之间距离有关),和通过每一个城市的税收(起点和终点城市不需要税收),问你从城市a到城市b的少花费,并输出少花费的路径。 因为要输出路径,可以用Floyd算法,只需在计算dist(a,b)的时候把经过的中间城市的税收加上就行了。 代码如下: #include #include #def

AC_Gibson的专栏 512

hdu 1385Minimum Transport Costfloyd算法加记录路径)

题意:运输货物,从一个地方到另一个地方所需要的小花费。中途经过的城市还要交税费,只有起点和终点不用交。并记录运输所走过的路径,在运费相同时输出字典序的路径,也就是小的路径(当不是短的路径)。 连接:http://acm.hdu.edu.cn/showproblem.php?pid=1385 解题思路:floyd算法,开一个数组(path)记录当前点上一个点的位置。在flo...

220

hdu 1385 floyd的妙用 Minimum Transport Cost

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

u012342878的专栏 398

hdu 1385 Minimum Transport Costfloyd过】【短路

Minimum Transport Cost Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9448    Accepted Submission(s): 2512 Problem Description The

mengxiang000000 501

HDU1385 Minimum Transport Costfloyd+标记路径)

Minimum Transport Cost Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11029    Accepted Submission(s): 3062 Problem Description Th

gyr 391
上一篇: hdu 1217 Arbitrage Flyod
下一篇: hdu 1224 Free DIY Tour Flyod
NMfloat
码龄1天 7粉丝 315原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值