您的位置:首页 > 房产 > 家装 > 网络规划设计师希赛_oa系统和erp系统区别_营销策略方案_永久免费客服系统有哪些软件

网络规划设计师希赛_oa系统和erp系统区别_营销策略方案_永久免费客服系统有哪些软件

2025/1/9 4:39:19 来源:https://blog.csdn.net/2301_79216282/article/details/143028169  浏览:    关键词:网络规划设计师希赛_oa系统和erp系统区别_营销策略方案_永久免费客服系统有哪些软件
网络规划设计师希赛_oa系统和erp系统区别_营销策略方案_永久免费客服系统有哪些软件
#include<stdio.h>
#include<stdlib.h>
float weight_map[3][3] = {0,6,13,10,0,4,5,100000,0};
float ch_weight_map[3][3];
int path_map[3][3], ch_path_map[3][3];
void generate_path_map() {int i, j;for (i = 0; i < 3;i++) {for (j = 0; j < 3;j++) {if (weight_map[i][j] == 0 ) {path_map[i][j] = -1;}else if (weight_map[i][j] == (100000)) {path_map[i][j] = -1;}else {path_map[i][j] = i;}}}
}
void floyd() {int floow;for (floow = 0; floow < 3;floow++) {for (int i = 0; i < 3;i++) {for (int j = 0; j < 3; j++) {if (weight_map[i][floow] >0 && weight_map[floow][j]>0) {if (weight_map[i][j] >= weight_map[i][floow] + weight_map[floow][j]) {ch_weight_map[i][j] = weight_map[i][floow] + weight_map[floow][j];ch_path_map[i][j] = path_map[floow][j];}else {ch_weight_map[i][j] = weight_map[i][j];ch_path_map[i][j] = path_map[i][j];}}else if(weight_map[i][floow] == 0 || weight_map[floow][j] == 0) {ch_weight_map[i][j] = weight_map[i][j];ch_path_map[i][j] = path_map[i][j];}}}for (int i = 0; i < 3;i++) {for (int j = 0; j < 3;j++) {weight_map[i][j] = ch_weight_map[i][j];path_map[i][j] = ch_path_map[i][j];}}}
}
int main() {generate_path_map();for (int i = 0; i < 3; i++) {for (int j = 0; j < 3; j++) {printf("%d ", path_map[i][j]);}printf("\n");}floyd();printf("\n");for (int i = 0; i < 3; i++) {for (int j = 0; j < 3; j++) {printf("%.2f ", weight_map[i][j]);}printf("\n");}printf("\n");for (int i = 0; i < 3; i++) {for (int j = 0; j < 3; j++) {printf("%d ", path_map[i][j]);}printf("\n");}return 0;
}

85bb92ed40994c9fb11f9bfb717d59ee.jpeg

后续的path_map矩阵可以反推出任意两点之间的最短路径

b5dfa173e91846b2a57802674a5ca0fa.png

 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com