ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 5393|回复: 9

[Excel 程序开发] [开_91]数念珠问题再次改编(比较变态)

[复制链接]

TA的精华主题

TA的得分主题

发表于 2006-3-10 15:37 | 显示全部楼层 |阅读模式
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

题目:有一个和尚,他有一串念珠,共七七49颗,都按1~49的顺序编号,他数念珠有个怪癖,比较变态,第1号开始数,数到第23颗珠子(即23号珠子)便从它开始拿23颗念珠(即23-45号)出来,接着又从46号珠子开始数,数到第22颗(即18号珠子)时也从它开始拿22颗念珠(即18-22、46-49、1-13号)出来,并把先拿出来的那些颗珠子(即23-45号珠子)放到该位置。接着又从14号珠子开始数。。。。。。如此循环,重复上面的做法后,最后取出的那个珠子的号码是多少?请大家编程帮他解决。
注意:规律是每次数的次数比上一次减1,取出念珠的颗数也比上一次减1,当次数减为0时停止,拿出来的珠子要放回到新的位置,放回后接下来数数要从该放回念珠之后开始。

规则挺复杂的,不知道说清没有,如果大家觉的这道题简单,下次再搞更变态的数法。

我的答案是5,不过我也不知道对不对

[此贴子已经被作者于2006-3-10 16:42:53编辑过]

TA的精华主题

TA的得分主题

发表于 2006-3-11 03:00 | 显示全部楼层

坐一次沙发,呵

以下是引用lg_cai在2006-3-10 15:37:08的发言:

题目:有一个和尚,他有一串念珠,共七七49颗,都按1~49的顺序编号,他数念珠有个怪癖,比较变态,第1号开始数,数到第23颗珠子(即23号珠子)便从它开始拿23颗念珠(即23-45号)出来,接着又从46号珠子开始数,数到第22颗(即18号珠子)时也从它开始拿22颗念珠(即18-22、46-49、1-13号)出来,并把先拿出来的那些颗珠子(即23-45号珠子)放到该位置(是否指放回23-45这个位置?)。接着又从14号珠子开始数。。。。。。如此循环,重复上面的做法后,最后取出的那个珠子的号码是多少?请大家编程帮他解决。
注意:规律是每次数的次数比上一次减1,取出念珠的颗数也比上一次减1,当次数减为0时停止,拿出来的珠子要放回到新的位置,放回后接下来数数要从该放回念珠之后开始。(不好意思,偶没明白这句话的意思)

规则挺复杂的,不知道说清没有,如果大家觉的这道题简单,下次再搞更变态的数法。

我的答案是5,不过我也不知道对不对


TA的精华主题

TA的得分主题

发表于 2006-3-12 16:01 | 显示全部楼层

我算得也是5

Sub xxx()
Dim all As Integer, first As Integer, i As Integer, j As Integer
Dim btmonk As New Collection, temp As New Collection
For i = 1 To 49
btmonk.Add i
Next

'pprint btmonk

first = 23
For j = 1 To first - 1
btmonk.Add btmonk(1)
btmonk.Remove 1
Next

'pprint btmonk

For j = 1 To first
temp.Add btmonk(1)
btmonk.Remove 1
Next

'pprint btmonk

Do While first > 0

first = first - 1

For j = 1 To first - 1
btmonk.Add btmonk(1)
btmonk.Remove 1
Next

'pprint btmonk

For j = 1 To first
temp.Add btmonk(1)
btmonk.Remove 1

Next

'pprint btmonk


For j = 1 To first + 1
btmonk.Add temp(1)
temp.Remove 1
Next

'pprint btmonk

Loop
MsgBox btmonk(btmonk.Count)
End Sub
'Private Sub pprint(ByVal btmonk As Collection)
'Dim x As String, j As Integer
'For j = 1 To btmonk.Count
'x = x & "," & btmonk(j)
'Next
'Debug.Print Mid(x, 2)
'End Sub

TA的精华主题

TA的得分主题

发表于 2006-3-12 16:03 | 显示全部楼层
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49
23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22
46,47,48,49,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22
18,19,20,21,22,46,47,48,49,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17
14,15,16,17
14,15,16,17,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45
39,40,41,42,43,44,45,14,15,16,17,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38
33,34,35,36,37,38
33,34,35,36,37,38,18,19,20,21,22,46,47,48,49,1,2,3,4,5,6,7,8,9,10,11,12,13
5,6,7,8,9,10,11,12,13,33,34,35,36,37,38,18,19,20,21,22,46,47,48,49,1,2,3,4
46,47,48,49,1,2,3,4
46,47,48,49,1,2,3,4,39,40,41,42,43,44,45,14,15,16,17,23,24,25,26,27,28,29,30,31,32
17,23,24,25,26,27,28,29,30,31,32,46,47,48,49,1,2,3,4,39,40,41,42,43,44,45,14,15,16
39,40,41,42,43,44,45,14,15,16
39,40,41,42,43,44,45,14,15,16,5,6,7,8,9,10,11,12,13,33,34,35,36,37,38,18,19,20,21,22
12,13,33,34,35,36,37,38,18,19,20,21,22,39,40,41,42,43,44,45,14,15,16,5,6,7,8,9,10,11
44,45,14,15,16,5,6,7,8,9,10,11
44,45,14,15,16,5,6,7,8,9,10,11,17,23,24,25,26,27,28,29,30,31,32,46,47,48,49,1,2,3,4
26,27,28,29,30,31,32,46,47,48,49,1,2,3,4,44,45,14,15,16,5,6,7,8,9,10,11,17,23,24,25
14,15,16,5,6,7,8,9,10,11,17,23,24,25
14,15,16,5,6,7,8,9,10,11,17,23,24,25,12,13,33,34,35,36,37,38,18,19,20,21,22,39,40,41,42,43
13,33,34,35,36,37,38,18,19,20,21,22,39,40,41,42,43,14,15,16,5,6,7,8,9,10,11,17,23,24,25,12
43,14,15,16,5,6,7,8,9,10,11,17,23,24,25,12
43,14,15,16,5,6,7,8,9,10,11,17,23,24,25,12,26,27,28,29,30,31,32,46,47,48,49,1,2,3,4,44,45
25,12,26,27,28,29,30,31,32,46,47,48,49,1,2,3,4,44,45,43,14,15,16,5,6,7,8,9,10,11,17,23,24
3,4,44,45,43,14,15,16,5,6,7,8,9,10,11,17,23,24
3,4,44,45,43,14,15,16,5,6,7,8,9,10,11,17,23,24,13,33,34,35,36,37,38,18,19,20,21,22,39,40,41,42
10,11,17,23,24,13,33,34,35,36,37,38,18,19,20,21,22,39,40,41,42,3,4,44,45,43,14,15,16,5,6,7,8,9
20,21,22,39,40,41,42,3,4,44,45,43,14,15,16,5,6,7,8,9
20,21,22,39,40,41,42,3,4,44,45,43,14,15,16,5,6,7,8,9,25,12,26,27,28,29,30,31,32,46,47,48,49,1,2
14,15,16,5,6,7,8,9,25,12,26,27,28,29,30,31,32,46,47,48,49,1,2,20,21,22,39,40,41,42,3,4,44,45,43
29,30,31,32,46,47,48,49,1,2,20,21,22,39,40,41,42,3,4,44,45,43
29,30,31,32,46,47,48,49,1,2,20,21,22,39,40,41,42,3,4,44,45,43,10,11,17,23,24,13,33,34,35,36,37,38,18,19
21,22,39,40,41,42,3,4,44,45,43,10,11,17,23,24,13,33,34,35,36,37,38,18,19,29,30,31,32,46,47,48,49,1,2,20
11,17,23,24,13,33,34,35,36,37,38,18,19,29,30,31,32,46,47,48,49,1,2,20
11,17,23,24,13,33,34,35,36,37,38,18,19,29,30,31,32,46,47,48,49,1,2,20,14,15,16,5,6,7,8,9,25,12,26,27,28
38,18,19,29,30,31,32,46,47,48,49,1,2,20,14,15,16,5,6,7,8,9,25,12,26,27,28,11,17,23,24,13,33,34,35,36,37
1,2,20,14,15,16,5,6,7,8,9,25,12,26,27,28,11,17,23,24,13,33,34,35,36,37
1,2,20,14,15,16,5,6,7,8,9,25,12,26,27,28,11,17,23,24,13,33,34,35,36,37,21,22,39,40,41,42,3,4,44,45,43,10
8,9,25,12,26,27,28,11,17,23,24,13,33,34,35,36,37,21,22,39,40,41,42,3,4,44,45,43,10,1,2,20,14,15,16,5,6,7
24,13,33,34,35,36,37,21,22,39,40,41,42,3,4,44,45,43,10,1,2,20,14,15,16,5,6,7
24,13,33,34,35,36,37,21,22,39,40,41,42,3,4,44,45,43,10,1,2,20,14,15,16,5,6,7,38,18,19,29,30,31,32,46,47,48,49
22,39,40,41,42,3,4,44,45,43,10,1,2,20,14,15,16,5,6,7,38,18,19,29,30,31,32,46,47,48,49,24,13,33,34,35,36,37,21
43,10,1,2,20,14,15,16,5,6,7,38,18,19,29,30,31,32,46,47,48,49,24,13,33,34,35,36,37,21
43,10,1,2,20,14,15,16,5,6,7,38,18,19,29,30,31,32,46,47,48,49,24,13,33,34,35,36,37,21,8,9,25,12,26,27,28,11,17,23
16,5,6,7,38,18,19,29,30,31,32,46,47,48,49,24,13,33,34,35,36,37,21,8,9,25,12,26,27,28,11,17,23,43,10,1,2,20,14,15
30,31,32,46,47,48,49,24,13,33,34,35,36,37,21,8,9,25,12,26,27,28,11,17,23,43,10,1,2,20,14,15
30,31,32,46,47,48,49,24,13,33,34,35,36,37,21,8,9,25,12,26,27,28,11,17,23,43,10,1,2,20,14,15,22,39,40,41,42,3,4,44,45
49,24,13,33,34,35,36,37,21,8,9,25,12,26,27,28,11,17,23,43,10,1,2,20,14,15,22,39,40,41,42,3,4,44,45,30,31,32,46,47,48
37,21,8,9,25,12,26,27,28,11,17,23,43,10,1,2,20,14,15,22,39,40,41,42,3,4,44,45,30,31,32,46,47,48
37,21,8,9,25,12,26,27,28,11,17,23,43,10,1,2,20,14,15,22,39,40,41,42,3,4,44,45,30,31,32,46,47,48,16,5,6,7,38,18,19,29
12,26,27,28,11,17,23,43,10,1,2,20,14,15,22,39,40,41,42,3,4,44,45,30,31,32,46,47,48,16,5,6,7,38,18,19,29,37,21,8,9,25
23,43,10,1,2,20,14,15,22,39,40,41,42,3,4,44,45,30,31,32,46,47,48,16,5,6,7,38,18,19,29,37,21,8,9,25
23,43,10,1,2,20,14,15,22,39,40,41,42,3,4,44,45,30,31,32,46,47,48,16,5,6,7,38,18,19,29,37,21,8,9,25,49,24,13,33,34,35,36
2,20,14,15,22,39,40,41,42,3,4,44,45,30,31,32,46,47,48,16,5,6,7,38,18,19,29,37,21,8,9,25,49,24,13,33,34,35,36,23,43,10,1
39,40,41,42,3,4,44,45,30,31,32,46,47,48,16,5,6,7,38,18,19,29,37,21,8,9,25,49,24,13,33,34,35,36,23,43,10,1
39,40,41,42,3,4,44,45,30,31,32,46,47,48,16,5,6,7,38,18,19,29,37,21,8,9,25,49,24,13,33,34,35,36,23,43,10,1,12,26,27,28,11,17
42,3,4,44,45,30,31,32,46,47,48,16,5,6,7,38,18,19,29,37,21,8,9,25,49,24,13,33,34,35,36,23,43,10,1,12,26,27,28,11,17,39,40,41
45,30,31,32,46,47,48,16,5,6,7,38,18,19,29,37,21,8,9,25,49,24,13,33,34,35,36,23,43,10,1,12,26,27,28,11,17,39,40,41
45,30,31,32,46,47,48,16,5,6,7,38,18,19,29,37,21,8,9,25,49,24,13,33,34,35,36,23,43,10,1,12,26,27,28,11,17,39,40,41,2,20,14,15,22
31,32,46,47,48,16,5,6,7,38,18,19,29,37,21,8,9,25,49,24,13,33,34,35,36,23,43,10,1,12,26,27,28,11,17,39,40,41,2,20,14,15,22,45,30
47,48,16,5,6,7,38,18,19,29,37,21,8,9,25,49,24,13,33,34,35,36,23,43,10,1,12,26,27,28,11,17,39,40,41,2,20,14,15,22,45,30
47,48,16,5,6,7,38,18,19,29,37,21,8,9,25,49,24,13,33,34,35,36,23,43,10,1,12,26,27,28,11,17,39,40,41,2,20,14,15,22,45,30,42,3,4,44
48,16,5,6,7,38,18,19,29,37,21,8,9,25,49,24,13,33,34,35,36,23,43,10,1,12,26,27,28,11,17,39,40,41,2,20,14,15,22,45,30,42,3,4,44,47
5,6,7,38,18,19,29,37,21,8,9,25,49,24,13,33,34,35,36,23,43,10,1,12,26,27,28,11,17,39,40,41,2,20,14,15,22,45,30,42,3,4,44,47
5,6,7,38,18,19,29,37,21,8,9,25,49,24,13,33,34,35,36,23,43,10,1,12,26,27,28,11,17,39,40,41,2,20,14,15,22,45,30,42,3,4,44,47,31,32,46
5,6,7,38,18,19,29,37,21,8,9,25,49,24,13,33,34,35,36,23,43,10,1,12,26,27,28,11,17,39,40,41,2,20,14,15,22,45,30,42,3,4,44,47,31,32,46
6,7,38,18,19,29,37,21,8,9,25,49,24,13,33,34,35,36,23,43,10,1,12,26,27,28,11,17,39,40,41,2,20,14,15,22,45,30,42,3,4,44,47,31,32,46
6,7,38,18,19,29,37,21,8,9,25,49,24,13,33,34,35,36,23,43,10,1,12,26,27,28,11,17,39,40,41,2,20,14,15,22,45,30,42,3,4,44,47,31,32,46,48,16
6,7,38,18,19,29,37,21,8,9,25,49,24,13,33,34,35,36,23,43,10,1,12,26,27,28,11,17,39,40,41,2,20,14,15,22,45,30,42,3,4,44,47,31,32,46,48,16
6,7,38,18,19,29,37,21,8,9,25,49,24,13,33,34,35,36,23,43,10,1,12,26,27,28,11,17,39,40,41,2,20,14,15,22,45,30,42,3,4,44,47,31,32,46,48,16
6,7,38,18,19,29,37,21,8,9,25,49,24,13,33,34,35,36,23,43,10,1,12,26,27,28,11,17,39,40,41,2,20,14,15,22,45,30,42,3,4,44,47,31,32,46,48,16,5

TA的精华主题

TA的得分主题

发表于 2006-3-12 23:40 | 显示全部楼层

不知道有没有理解错误,用数组方法答案是20

Option Explicit
Option Base 1
Dim PrayerBeads(), PreGetBeads()

Sub GetBead()
Dim sArrb
Dim i As Integer
ReDim PrayerBeads(1 To 26)
ReDim PreGetBeads(1 To 23)
sArrb = "46,47,48,49,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22"
sArrb = VBA.Split(sArrb, ",")

For i = 1 To 23
PreGetBeads(i) = i + 22
Next
For i = 0 To UBound(sArrb)
PrayerBeads(i + 1) = sArrb(i)
Next

Beads 22

End Sub


Sub Beads(iNum As Integer)

Dim i As Integer, j As Integer, k As Integer, tmpBeads(), iPos As Integer, iPos0 As Integer
'========================================================
'iNum=0时结束
If iNum = 0 Then MsgBox "最后取出的念珠号码为: " & PreGetBeads(1), vbOKOnly, "数念珠": Exit Sub

'========================================================
'将上次取出结果保存在tmpBeads数组中
tmpBeads = PreGetBeads

'定义本次取出的念珠数组
ReDim PreGetBeads(1 To iNum)
'=======================================================
'从n位开始取出念珠,并存入数组PreGetBeads,并将原念珠数组中相应位置号码置0
k = 0
For i = iNum To 2 * iNum - 1
If i > UBound(PrayerBeads) Then
k = k + 1
iPos = k
Else
iPos = i
End If
PreGetBeads(i - iNum + 1) = PrayerBeads(iPos)
PrayerBeads(iPos) = 0
Next
'==============================================
'取得剩余号码

Dim tmp()
ReDim tmp(1 To UBound(PrayerBeads) - iNum)
Debug.Print UBound(tmp)
k = 0: j = 0
For i = iPos + 1 To iPos + UBound(PrayerBeads)
If i > UBound(PrayerBeads) Then
k = k + 1
iPos0 = k
Else
iPos0 = i
End If

If PrayerBeads(iPos0) <> 0 Then
j = j + 1
tmp(j) = PrayerBeads(iPos0)
End If
Next

'===============================================
'生成新数组
PrayerBeads = tmpBeads
ReDim Preserve PrayerBeads(1 To 49 - iNum)
k = 0
For i = (UBound(tmpBeads) + 1) To UBound(PrayerBeads)
k = k + 1
PrayerBeads(i) = tmp(k)
Next

Beads iNum - 1

End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-3-13 10:35 | 显示全部楼层
以下是引用northwolves在2006-3-12 16:01:59的发言:

我算得也是5

Sub xxx()
Dim all As Integer, first As Integer, i As Integer, j As Integer
Dim btmonk As New Collection, temp As New Collection
For i = 1 To 49
btmonk.Add i
Next

'pprint btmonk

first = 23
For j = 1 To first - 1
btmonk.Add btmonk(1)
btmonk.Remove 1
Next

'pprint btmonk

For j = 1 To first
temp.Add btmonk(1)
btmonk.Remove 1
Next

'pprint btmonk

Do While first > 0

first = first - 1

For j = 1 To first - 1
btmonk.Add btmonk(1)
btmonk.Remove 1
Next

'pprint btmonk

For j = 1 To first
temp.Add btmonk(1)
btmonk.Remove 1

Next

'pprint btmonk


For j = 1 To first + 1
btmonk.Add temp(1)
temp.Remove 1
Next

'pprint btmonk

Loop
MsgBox btmonk(btmonk.Count)
End Sub
'Private Sub pprint(ByVal btmonk As Collection)
'Dim x As String, j As Integer
'For j = 1 To btmonk.Count
'x = x & "," & btmonk(j)
'Next
'Debug.Print Mid(x, 2)
'End Sub

正确,用Collection来解决倒是挺方便的,我用的是数组

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-3-13 11:21 | 显示全部楼层
以下是引用清风_ll在2006-3-12 23:40:46的发言:

不知道有没有理解错误,用数组方法答案是20


'生成新数组
PrayerBeads = tmpBeads
ReDim Preserve PrayerBeads(1 To 49 - iNum)
k = 0
For i = (UBound(tmpBeads) + 1) To UBound(PrayerBeads)
k = k + 1
PrayerBeads(i) = tmp(k)
Next

Beads iNum - 1

End Sub

谢谢清风兄参与,你的理解有一点问题,就是把念珠放回去后应该从它的后面接着数,而你的代码是从放回去的第一颗开始数。

我把最后几句改了一下

'===============================================
'生成新数组
ReDim Preserve PrayerBeads(1 To 49 - iNum)
For i = 1 To 49 - iNum
If i <= UBound(tmp) Then
PrayerBeads(i) = tmp(i)

Else
PrayerBeads(i) = tmpBeads(i - UBound(tmp))
End If
Next

Beads iNum - 1

TA的精华主题

TA的得分主题

发表于 2006-3-14 10:28 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

原来是这个意思啊

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-3-17 09:27 | 显示全部楼层

我的解法

Sub cai()
Dim arr()
Dim i%, s1%, s2%, z1%, c1%, q1%, q2%
s1 = 49
s2 = 23
ReDim arr(0 To s1)

For i = 0 To s1 - 1
arr(i) = i + 1
Next i
arr(s1) = 1

Do While s2 > 0

For i = 1 To s2 - 1
z1 = arr(z1)
Next i
z2 = z1
q1 = arr(z1)

For i = 1 To s2
z1 = arr(z1)
Next i
q2 = z1

If c1 = 0 Then
arr(z2) = arr(z1)
Else
arr(c2) = arr(z1)
arr(z2) = c1

End If
c1 = q1
c2 = q2
s2 = s2 - 1
Loop
MsgBox "答案为 " & q1
End Sub

TA的精华主题

TA的得分主题

发表于 2013-5-5 20:06 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
来个短的程序:
'字符串法
Sub getLastBead()
    n = 49: m = 23
    beads = "": removedBeads = ""
    For i = 1 To n: beads = beads & Format(i, "00"): Next
    startNo = 0
    For i = m To 1 Step -1
        NBs = Len(beads) / 2
        startNo = (startNo + i - 1) Mod NBs
        tempBeads = Right(beads, 2 * (NBs - startNo)) & Left(beads, 2 * startNo)
        beads = removedBeads & Right(tempBeads, 2 * (NBs - i))
        startNo = Len(removedBeads) / 2
        removedBeads = Left(tempBeads, 2 * i)
    Next
    Debug.Print Val(removedBeads)
End Sub
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-25 12:19 , Processed in 0.046407 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表