永发信息网

用vb.netl编写的floyd算法求两点间的最短路径,怎么输出path经过的顶点序列?

答案:2  悬赏:0  手机版
解决时间 2021-03-08 16:58
  • 提问者网友:鐵馬踏冰河
  • 2021-03-07 19:01
用vb.netl编写的floyd算法求两点间的最短路径,怎么输出path经过的顶点序列?
最佳答案
  • 五星知识达人网友:逐風
  • 2021-03-07 20:16
Function Min(x() as integer,y() as integer) as doubledim i,j,k,a dim m() as doubledim s() as stringdim mins as stringredim m(ubound(x),ubound(x))redim s(ubound(x),ubound(x))for i=1 to ubound(x)-1 '从起始点0点到i点的距离m(i,0)=((x(i)-x(0))^2+(y(i)-y(0))^2)^0.5s(i,0)=0- & cstr(i)next'从起始点开始经过K个点后到达i点的最短距离m(i,k),s为各点的连线如0-3-2-1-4for k=1 to ubound(x)-2for i=1 to ubound(x)-1m(i,k)=10^307for j=1 to ubound(x)-1if instr(s(j,k-1),cstr(i))=0 then'避免重复走一点a=((x(i)-x(j))^2+(y(i)-y(j))^2)^0.5if a+m(j,k-1)<m(i,k) thenm(i,k)=a+m(j,k-1)s(i,k)=s(j,k-1) & - & cstr(i)endifend ifnext nextnext'计算经过各点后到达最后一个点的最短距离min=10^307for j=1 to ubound(x)-1a=((x(ubound(x))-x(j))^2+(y(ubound(x))-y(j))^2)^0.5if a+m(j,ubound(x)-2)<min thenmin=a+m(j,ubound(x)-2)mins=s(j,ubound(x)-2) & - & cstr(ubound(x))end ifnextmsgbox 最短距离: & min & vbcrlf & 最短路径: & minsEnd functionprivate sub Command1_Clickdim x(5) as integerdim y(5) as integerdim m as doublex(0)=0y(0)=0x(1)=40y(1)=600.x(5)=1000y(5)=1000m=min(x,y)End sub
全部回答
  • 1楼网友:长青诗
  • 2021-03-07 20:40
你的回答很对
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯