hdu 1385 floyd记录路径
可以用floyd 直接记录相应路径
太棒了!
http://blog.csdn.net/ice_crazy/article/details/7785111
#include"stdio.h"
#include"string.h" int n;
int tax[111];
int map[111][111];
int path[111][111]; void floyd()
{
int temp;
int k,i,l; for(i=1;i<=n;i++)
for(l=1;l<=n;l++)
path[i][l]=l; for(k=1;k<=n;k++)
{
for(i=1;i<=n;i++)
{
for(l=1;l<=n;l++)
{
temp=map[i][k]+map[k][l]+tax[k];
if(temp<map[i][l])
{
map[i][l]=temp;
path[i][l]=path[i][k];
}
else if(temp==map[i][l])
{
if(path[i][l]>path[i][k])
path[i][l]=path[i][k];
}
}
}
}
} int main()
{
int i,l;
int temp;
int s,e; while(scanf("%d",&n),n)
{
for(i=1;i<=n;i++)
for(l=1;l<=n;l++)
{
scanf("%d",&temp);
if(temp==-1) map[i][l]=11111111;
else map[i][l]=temp;
} for(i=1;i<=n;i++) scanf("%d",&tax[i]); floyd(); while(scanf("%d%d",&s,&e)!=-1)
{
if(s==-1 && e==-1) break;
printf("From %d to %d :\n",s,e);
printf("Path: %d",s);
temp=s;
while(temp!=e)
{
printf("-->%d",path[temp][e]);
temp=path[temp][e];
}
printf("\n");
printf("Total cost : %d\n\n",map[s][e]);
}
}
return 0;
}
hdu 1385 floyd记录路径的更多相关文章
- 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 // ...
- *HDU 1385 最短路 路径
Minimum Transport Cost Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- ACM/ICPC 之 Floyd+记录路径后继(Hdu1385(ZOJ1456))
需要处理好字典序最小的路径 HDU1385(ZOJ1456)-Minimum Transport //Hdu1385-ZOJ1456 //给定邻接矩阵,求给定起点到终点的最短路径,若有相同路长的路径按 ...
- HDU 1385 Minimum Transport Cost( Floyd + 记录路径 )
链接:传送门 题意:有 n 个城市,从城市 i 到城市 j 需要话费 Aij ,当穿越城市 i 的时候还需要话费额外的 Bi ( 起点终点两个城市不算穿越 ),给出 n × n 大小的城市关系图,-1 ...
- HDU1385 (Floyd记录路径)
Minimum Transport Cost Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- hdu 1026 bfs+记录路径
题意:从0,0点出发到n-1,m-1点,路上的数字代表要在这个点额外待多少秒,求最短的路 递归输出路径即可 #include<cstdio> #include<iostream> ...
- hdu 1385 floyd字典序
Minimum Transport Cost Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- hdu 1385(Floyed+打印路径好题)
Minimum Transport Cost Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- hdu 1026 Ignatius and the Princess I (bfs+记录路径)(priority_queue)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1026 Problem Description The Princess has been abducted ...
随机推荐
- java中tcp小样例
服务端: ServerSocket service = new ServerSocket(7777); Socket socket = service.accept(); InputStream in ...
- Tomcat报错合集
1.java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start c ...
- Linux 强行终止
kill -9 pid pid是进程号 -9 代表的是数字 INT 2 这个就是你在bash下面用Ctrl+C 来结束一个程序时,bash会向进程发送这个信号,默认的,进程收到这个程序会结束. 你可以 ...
- ProjectRuler 算法练习之 位数组成字符串同样的整数
Problem :It can be seen that the number, 125874, and its double, 251748, contain exactly the same di ...
- 扩展函数之 IsWhat 简单好用
代码实现: /***扩展函数名细***/ //[IsInRange] ; //以前写法 & num < ) { } //现在写法 , )) { } //datetime类型也支持 //[ ...
- 部署微信定位精灵APK到Genymotion
- Qt5.9 WebChannel
Qt WebChannel enables peer-to-peer communication between a server (QML/C++ application) and a client ...
- JavaScrip——插入地图
具体操作步骤:1.百度搜索:百度地图生成器 2.打开第一个,复制网址http://api.map.baidu.com/lbsapi/creatmap/index.html,打开3.页面显示为 4.根据 ...
- ItemArray DataRow对象的RowState和DataRowVersion属性特点
DataTable.Rows[i].ItemArray DataTable.Rows表示所有行的集合DataTable.Rows[i]加上下标表示其中某一行DataTable.Rows[i].Item ...
- 利用javascript(自定义事件)记录尺寸可变元素的尺寸变化过程
1.效果图 2.源码 <%@ page contentType="text/html;charset=UTF-8" language="java" %&g ...