最短路径-弗洛伊德算法
来源:互联网 发布:centos lamp环境搭建 编辑:程序博客网 时间:2024/05/01 08:32
void SchoolMap::FindRoad(int a, int b, int &StepNUM, int &Dis,int Step[]){int D[11][11], Path[11][11], i, j, k; for (int i = 0; i<BudingNUM; ++i)for (int j = 0; j<BudingNUM; ++j){if (i == j){D[i][j] = 0; Path[i][j] = 0;}else{D[i][j] = Road[i][j];if (D[i][j] < 999) {Path[i][j] = j;}else Path[i][j] = -1;}}for (int k = 0; k < BudingNUM; ++k){for (int i = 0; i < BudingNUM; ++i){for (int j = 0; j < BudingNUM; ++j){if(D[i][j]>(D[i][k]+D[k][j])) {D[i][j] = D[i][k] + D[k][j];Path[i][j] = Path[i][k]; }}}Dis = D[a][b];}Budings[a].ShowName();while (a != b){ cout << "-"; Budings[Path[a][b]].ShowName(); a = Path[a][b];}cout << endl;}
我认为这个算法最重要的地方在于Path 保存点的那一处:
例如我走的是0-5这条路线 压经过0-3和3-5最短 而0-3又要经过0-1和1-3最短 那么用Path保存 当只允许走1号顶点的时候(k=1)时候 Path[i][j] = Path[i][k];将Path[i][k];这个值保存 k=1时 这个值为1 因此0-3=1 当走0-5的时候在3号顶点的时候(k=3)时Path[0][5]=Path[0][3] 而Path[0][3]的值正好是必须经过0-1时候的赋值 以此类推 Path就很好的保存了走这条路线每一条最短的必经路线将其值从底传至顶部保存下来 下一次访问 通过a = Path[a][b];如果a-b之间还有最短路径 那么其中必然存在传上来的值 会走那条路线
0 0
- 弗洛伊德最短路径算法
- 弗洛伊德算法--最短路径
- 最短路径-弗洛伊德算法
- 弗洛伊德最短路径算法
- 最短路径(弗洛伊德算法)
- 最短路径--弗洛伊德算法
- 最短路径:弗洛伊德算法
- 弗洛伊德最短路径算法
- 弗洛伊德最短路径算法
- 最短路径---弗洛伊德算法
- 最短路径(弗洛伊德算法)
- 最短路径—弗洛伊德算法
- 最短路径之弗洛伊德算法(Floyd)
- 弗洛伊德变种算法计算最短路径
- 图--最短路径--弗洛伊德算法
- 最短路径之Floyd(弗洛伊德)算法
- Floyd Warshall 弗洛伊德算法---最短路径
- 最短路径--弗洛伊德(Floyd)算法
- telnet访问web服务器
- C++中typedef的用法
- mac系统使用lookup file.vim的问题
- 行业危机
- Android 实现滑动的几种方法(三)scrollTo 与 scrollBy
- 最短路径-弗洛伊德算法
- s3c2440 usb host
- 博客的开始,介绍一些自己,我是这样的一个程序员
- Mysql日志详解
- 黑马程序员 JavaSE-06 面向对象(下)
- 断点续传的原理剖析与实例讲解
- INVALID_USER_SCODE
- debug和release版本dll混用导致的问题
- struts动态方法调用