超速行车问题的数学模型解决方案内容摘要:

G=(mgraph *)malloc(sizeof(mgraph))。 cout欢迎进入公路交通网查询系统 .endl。 createmgraph(G)。 while(xz!=0) { cout*******求城市之间最短路径 *******endl。 cout================================endl。 cout请选择: 1 查询 0 结束 endl。 cout================================endl。 cinxz。 12 coutendl。 if(xz) { floyd(G)。 cout城市名称及编号如下 endl。 cout 1 2 3 4 5 endl。 cout 6 7 8 9 10 endl。 cout 11 12 13 14 15 endl。 cout 16 17 18 19 20 endl。 cout 21 22 23 24 25 endl。 cout 26 27 28 29 30 endl。 cout 31 32 33 34 35 endl。 cout 36 37 38 39 40 endl。 cout 41 42 43 44 45 endl。 cout 46 47 48 49 50 endl。 cout 51 52 53 54 55 endl。 cout 56 57 58 59 60endl。 cout 61 62 63 64 65endl。 cout 66 67 68 69 70 endl。 cout 71 72 73 74 75 endl。 cout 76 77 78 79 80endl。 cout 81 82 83 84 85endl。 cout 86 87 88 89 90endl。 cout 91 92 93 94 95 endl。 cout 96 97 98 99 100endl。 cout请输入源点和终点 : endl。 cinvw。 k=p[v][w]。 //k 为起点 i的后继顶点 if(k==0) cout无路径。 endl。 else { cout所求最短路径为: endl。 coutv。 while(k!=w) { coutk。 k=p[k][w]。 } coutw。 cout路径长度为: d[v][w]公里 endl。 } coutendl。 13 } else cout谢谢使用,祝您旅途愉快。 endl。 } } 花费最少路线 include include include //输入输出流 include define mvnum 1000//最大定点数 define maxint 9999999 typedef char vertextype。 typedef int adjmatrix。 struct mgraph { vertextype vexs[mvnum]。 //顶点数组,假定为 char 型 adjmatrix arcs[mvnum][mvnum]。 //临街矩阵,假定为 int 型 }。 double d[mvnum][mvnum],p[mvnum][mvnum]。 //////////// void createmgraph(mgraph *G) {//采用邻接矩阵表示法构造无向图 G int i,j,k,w。 ifstream graphlist(,ios::in)。 //定义一个流对象,并且和文件关联 for(i=1。 i=100。 i++) Gvexs[i]=(char)i。 for(i=1。 i=100。 i++) for(j=1。 j=100。 j++) Garcs[i][j]=maxint。 //初始化邻接矩阵 for(k=1。 k=180。 k++) {//从磁盘文件接受数据构造网 graphlisti。 graphlistj。 graphlistw。 Garcs[i][j]=w。 Garcs[j][i]=Garcs[i][j]。 //构造无向网 } //cout图的存储结构建立完毕。 endl。 ()。 //关闭文件 14 } /////////////// void floyd(mgraph *G) { int i,j,k。 for(i=1。 i=100。 i++)//设置路径长度 D和路径初值 for(j=1。 j=100。 j++) { if(Garcs[i][j]!=maxint) p[i][j]=j。 else p[i][j]=0。 d[i][j]=Garcs[i][j]。 } for(k=1。 k=100。 k++) { for(i=1。 i=100。 i++) for(j=1。 j=100。 j++) { if (d[i][k]+d[k][j]d[i][j]) { d[i][j]=d[i][k]+d[k][j]。 p[i][j]=p[i][k]。 } } } } //////////// void main() { mgraph *G。 int v,w,k。 int xz=1。 G=(mgraph *)malloc(sizeof(mgraph))。 cout欢迎进入铁路交通网查询系统 .endl。 createmgraph(G)。 while(xz!=0) { cout*******求城市之间花费最少 *******endl。 cout================================endl。 cout请选择: 1 查询 0 结束 endl。 cout================================endl。 cinxz。 15 coutendl。 if(xz) { floyd(G)。 cout城市名称及编号如下 endl。 cout 1 2 3 4 5 endl。 cout 6 7 8 9 10 endl。 cout 11 12 13 14 15 endl。 cout 16 17 18 19 20 endl。 cout 21 22 23 24 25 endl。 cout 26 27 28 29 30 endl。 cout 31 32 33 34 35 endl。 cout 36 37 38 39 40 endl。 cout 41 42 43 44 45 endl。 cout 46 47 48 49 50 endl。 cout 51 52 53 54 55 endl。 cout 56 57 58 59 60endl。 cout 61 62 63 64 65endl。 cout 66 67 68 69 70 endl。 cout 71 72 73 74 75 endl。 cout 76 77 78 79 80endl。 cout 81 82 83 84 85endl。 cout 86 87 88 89 90endl。 cout 91 92 93 94 95 endl。 cout 96 97 98 99 100endl。 cout请输入源点和终点 : endl。 cinvw。 k=p[v][w]。 //k 为起点 i的后继顶点 if(k==0) cout无路径。 endl。 else { cout所求花费最少为: endl。 coutv。 while(k!=w) {。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。