vb至少发到多少张时没人手中贺卡书相同
有11各人围成一圈发贺卡,一次给13681125710……号发至少发到多少张时每个人手中的贺卡数相同...
有11 各人围成一圈发贺卡,一次给1 3 6 8 11 2 5 7 10 ……号发至少发到多少张时每个人手中的贺卡数相同
展开
1个回答
展开全部
Private Sub Command1_Click()
Dim a(11) As Long
Dim i As Long
Dim step As Long '递增规律2,3
i = 1
Dim k As Long '总发糖数
Dim j As Long
Dim isFindOk As Boolean
isFindOk = False
step = 2
While Not isFindOk
a(i) = a(i) + 1 '发糖一块
k = k + 1
If k Mod 11 = 0 Then
'发糖数是11倍数时才有可能相同
isFindOk = True
For j = 2 To 11
If a(j) <> a(j - 1) Then
'发糖数不同
isFindOk = False
Exit For
End If
Next
End If
i = i + step
If step = 2 Then
step = 3
Else
step = 2
End If
If i > 11 Then
i = i - 11
End If
Wend
MsgBox "发:" & k & "张时,每人贺卡相同"
End Sub
Dim a(11) As Long
Dim i As Long
Dim step As Long '递增规律2,3
i = 1
Dim k As Long '总发糖数
Dim j As Long
Dim isFindOk As Boolean
isFindOk = False
step = 2
While Not isFindOk
a(i) = a(i) + 1 '发糖一块
k = k + 1
If k Mod 11 = 0 Then
'发糖数是11倍数时才有可能相同
isFindOk = True
For j = 2 To 11
If a(j) <> a(j - 1) Then
'发糖数不同
isFindOk = False
Exit For
End If
Next
End If
i = i + step
If step = 2 Then
step = 3
Else
step = 2
End If
If i > 11 Then
i = i - 11
End If
Wend
MsgBox "发:" & k & "张时,每人贺卡相同"
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询