将随机值映射到区间c语言,数组a存储降序排列的m个数据,数组b中存储的是升序排列的n个数据,且两个数组中存储的数据为区间[1,20]范围内的不重复的随机整数。现将两个数组的数据合并到c数组中,使c数组...

(2)

请在划线处填入合适的代码。

Const n = 5      '村庄数

Const m = 8      '管道线路数

Dim pointAB(1 To 2 * m) As Integer      '存储连接的两个村庄节点

Dim length(1 To m) As Integer      '存储两个村庄之间的距离

Dim res(1 To 100) As Integer      '存储管道规划结果

Private Sub Form_Load()

'村庄节点数据存储在pointAB数组,两个村庄的距离数据存储在length数组。

'如图c所示,(V1,V3)边距离为1,则pointAB(1)=1,pointAB(2)=3,length(1)=1;

(V1,V2)边距离为6,则pointAB(3)=1,pointAB(4)=2,length(2)=6;其他依次类推,代码略。

End Sub

Function check(x As Integer) As Integer      '判断x节点是否已在规划中

check = 0

For i = 1 To 100

If x = res(i) Then check = 1: Exit Function

Next i

End Function

Private Sub Command1_Click()

Dim i As Integer, j As Integer, tmp As Integer

Dim total As Integer, sum As Integer

For i = 1 To m - 1

For j = m To i + 1 Step -1

If ________ Then

tmp= pointAB(2 * j - 1) :pointAB(2 * j - 1) = pointAB(2

* j - 3) :pointAB(2 * j - 3) = tmp

tmp = pointAB(2 * j) : pointAB(2 * j) = pointAB(2 * j -

2) :pointAB(2 * j - 2) = tmp

tmp = length(j): length(j) = length(j - 1): length(j -

1) = tmp

End If

Next j

Next i

'开始规划管道

total = 1

res(1) = pointAB(1): res(2) = pointAB(2)

sum = length(1)

Do While total < ________

For i = 2 To m

If ________ Then

total = total + 1

res(2 * total - 1) = pointAB(2 * i - 1)

res(2 * total) = pointAB(2 * i)

sum = sum + length(i)

Exit For

End If

Next i

Loop

'输出连通结果res 以及管道总长度sum,代码略。

End Sub

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值