当前位置:首页 >> 学科竞赛 >>

蒙提霍尔问题的概率 蒙特霍问题 三门问题 Monty Hall Problem


下面是VB 6.0代码:新建一个Txt文档,复制下面代码保存为.Frm 就可以使用了
VERSION 5.00
Begin VB.Form Form1
Caption = "蒙提霍尔问题/三门问题;qq:1457070900"
ClientHeight = 3795
ClientLeft = 60
ClientTop = 450
ClientWidth = 4500
ForeColor = &H0000FFFF&
LinkTopic = "Form1"
ScaleHeight = 3795
ScaleWidth = 4500
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton cmdno
Caption = "不换"
Height = 495
Left = 1800
TabIndex = 6
Top = 1440
Width = 735
End
Begin VB.CommandButton cmdyes
Caption = "换"
Height = 495
Left = 960
TabIndex = 5
Top = 1440
Width = 735
End
Begin VB.TextBox Text2
Height = 1335
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 2
Top = 2280
Width = 4215
End
Begin VB.CommandButton cmdopen
BackColor = &H0000FF00&
Caption = "开门"
Height = 495
Left = 120
TabIndex = 1
Top = 1440
Width = 735
End
Begin VB.Frame Frame1
Caption = "计算概率"
Height = 1815
Left = 2640
TabIndex = 7
Top = 240
Width = 1695
Begin VB.CommandButton Command1
Caption = "开始"
Height = 375
Left = 240
TabIndex = 12
Top = 840
Width = 1215
End
Begin VB.TextBox Text1
Height = 270
Left = 720
TabIndex = 11
Text = "100000"
Top = 480
Width = 735
End
Begin VB.CheckBox Check1
Caption = "Check1"
Height = 255
Left = 720
TabIndex = 8
Top = 240
Width = 255
End
Begin VB.Label Label3
Caption = "Label3"
Height = 375
Left = 120
TabIndex = 13
Top = 1320
Width = 1455
End
Begin VB.Label Label2
Caption = "次数:"
Height = 255
Left = 240
TabIndex = 10
Top = 480
Width = 615
End
Begin VB.Label Label1
Caption = " 换:"
Height = 255
Left = 240
TabIndex = 9
Top = 240
Width = 735
End
End
Begin VB.Label door
BackColor = &H80000008&
Caption = "门2"
ForeColor = &H0000FFFF&
Height = 855
Index = 2
Left = 1920
TabIndex = 4
Top = 360
Width = 495
End
Begin VB.Label door
BackColor = &H80000008&
Caption = "门1"
ForeColor = &H0000FFFF&
Height = 855
Index = 1
Left = 1080
TabIndex = 3
Top = 360
Width = 495
End
Begin VB.Label door
BackColor = &H80000008&
Caption = "门0"
ForeColor = &H0000FFFF&
Height = 855
Index = 0
Left = 240
TabIndex = 0
Top = 360
Width = 495
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim men(3) As Boolean
Dim car, sel, od, cishuc, cishus As Long
Dim opened, clicked As Boolean

Private Sub cmdno_Click()
If opened = False Then
MsgBox "先单击开门!"
Else
If car <> sel Then cishus = cishus + 1: Text2 = "第" & cishuc + cishus & "次:" & "车在门" & car & ",首选门" & sel & ",开门" & od & ",不换则失败" & vbCrLf & Text2 Else cishuc = cishuc + 1: Text2 = "第" & cishuc + cishus & "次:" & "车在门" & car & ",首选门" & sel & ",开门" & od & ",不换则成功!" & vbCrLf & Text2
Form_Load
End If
End Sub

Private Sub cmdopen_Click()
If clicked = False Then
MsgBox "先单击一个门!"
Else
If opened = True Then
MsgBox "只能开一次门!"
Else
If men(sel) = False Then
For i = 0 To 2
If men(i) = False And sel <> i Then od = i: door(i).BackColor = &HFF00&
Next
Else
Do
od = Int(Rnd * 3)
Loop While od = sel
door(od).BackColor = &HFF00&
End If
opened = True
End If
End If
End Sub

Private Sub cmdyes_Click()
If opened = False Then
MsgBox "先单击开门!"
Else
If car = sel Then cishus = cishus + 1: Text2 = "第" & cishuc + cishus & "次:" & "车在门" & car & ",首选门" & sel & ",开门" & od & ",换则失败" & vbCrLf & Text2 Else cishuc = cishuc + 1: Text2 = "第" & cishuc + cishus & "次:" & "车在门" & car & ",首选门" & sel & ",开门" & od & ",换则成功!" & vbCrLf & Text2
Form_Load
End If
End Sub

Private Sub Command1_Click()
cs = Val(Text1)
For i = 1 To cs
sel = Int(Rnd * 3)
If Check1 = 0 Then
If car <> sel Then cishus = cishus + 1 Else cishuc = cishuc + 1
Else
If car = sel Then cishus = cishus + 1 Else cishuc = cishuc + 1
End If
Next
Label3 = "成功率:" & cishuc / (cishuc + cishus) * 100 & "%"
cishus = 0
cishuc = 0
End Sub

Private Sub door_Click(Index As Integer)
clicked = True
sel = Index
For i = 0 To 2
door(i).BackColor = &H0&
Next
door(sel).BackColor = &HFF&
End Sub

Private Sub Form_Load()
opened = False
clicked = False
For i = 0 To 2
men(i) = False
door(i).BackColor = &H0&
Next
car = Int(Rnd * 3)
men(car) = True
End Sub


相关文章:
三门问题
三门问题_数学_自然科学_专业资料。三门问题 编辑锁定 三门问题(Monty Hall problem)亦称为蒙提霍尔问题蒙特霍问题或蒙提霍尔悖论,大致 出自美国的电视游戏节目 ...
由三门问题看概率论
三门问题(Monty Hall problem) ,是一个源自博弈论的数学游戏问题,大致出自美国的 电视游戏节目 Let's Make a Deal。问题的名字来自该节目的主持人蒙提?霍尔(...
对策理论的实际应用
亦称为蒙提霍尔问题蒙特霍问题或蒙 提霍尔悖论、三门问题(Monty Hall problem...因 为三种情况中有两种是透过转换选择而赢的,所以透过转换 选择而赢的概率是 ...
概率论论文
直觉与概率论摘要:大二概率论课程结束了,在一学期的学习过程中,我们掌握了很多...三 三门问题 三门问题( Monty Hall problem )亦称为蒙提霍尔问题蒙特霍问题...
古典概型学案(二)
整除的概率 四、 课后反思 附录:三门问题三门问题——亦称为蒙提霍尔问题蒙特霍问题或蒙提霍尔悖论(Monty Hall problem) 三门问题(Monty Hall problem) ,是一...
金融
谁成为倒霉蛋的概率一样, 所以换与不换都一样 ___ 没有看懂你的意思:(关注...经典的蒙提霍尔问题, 亦称为蒙特霍问题三门问题 (Monty Hall Problem) ,是...
概率知识在实际生活中的应用
3.3 “三门问题三门问题(Monty Hall problem)亦称为蒙提霍尔问题蒙特霍问题或蒙提 霍尔悖论,大致出自美国的电视游戏节目 Let's Make a Deal.问题名字来自...
三门问题
什么是三门问题 三门问题(Monty Hall problem) ,...如上文所述,蒙提霍尔问题是游戏节目环节的一个引申...因此,得到汽车的概率是 1/3。 门1 汽车 山羊 门...
有趣的三门问题
有趣的三门问题邓超 (福建省福州市第十八中学 350001) 美国电视游戏节目 Let's Make a Deal 的主持人蒙提· 霍尔(Monty Hall)在一次节目中 让参赛者做了一个...
三门问题研究
9 i 三门问题研究摘要:本文首先介绍了概率论的起源和创立以及著名的三门问题(即蒙提霍尔问题)及其 研究思路, 并针对该问题利用贝叶斯公式计算得到了三门问题的正确...
更多相关标签: