|
楼主 |
发表于 2017-12-21 07:17
|
显示全部楼层
蓝板出的题目地址链接:
[第119期]假如你是无人驾驶车上的电脑,你想好了怎么走吗?
http://club.excelhome.net/thread-1379620-1-1.html
(出处: ExcelHome技术论坛)
截止日期是12月20日,今天贴出自己的解决办法
- Public d
- Public a
- Public arr
- Sub lqxs_zd()
- Set d = CreateObject("scripting.dictionary")
- arr = Sheets(2).[a1].CurrentRegion
- m = WorksheetFunction.Sum(Sheets(2).Columns(3))
- d("E") = 0
- a = 6
- dg ("E")
- Set Rng = Rows(2).Find(WorksheetFunction.Min(Rows(2)), lookat:=xlWhole)
- [c2] = Rng.Value
- [d2] = Cells(1, Rng.Column)
- End Sub
- Sub dg(str1 As String)
- For j = 2 To UBound(arr)
- If (arr(j, 1) = "B" And arr(j, 2) = str1) Or (arr(j, 2) = "B" And arr(j, 1) = str1) Then
- d("B") = arr(j, 3)
- Cells(1, a) = Join(d.keys, "-")
- Cells(2, a) = WorksheetFunction.Sum(d.items)
- a = a + 1
- d.Remove "B"
- Else
- If arr(j, 1) = str1 And Not d.exists(arr(j, 2)) Then
- d(arr(j, 2)) = arr(j, 3)
- dg (arr(j, 2))
- Else
- If arr(j, 2) = str1 And Not d.exists(arr(j, 1)) Then
- d(arr(j, 1)) = arr(j, 3)
- dg (arr(j, 1))
- End If
- End If
- End If
- Next j
- d.Remove str1
- End Sub
复制代码
使用递归+字典求最短路径 |
评分
-
1
查看全部评分
-
|