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

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


下面是VB 6.0代码:新建一个Txt文档,复制下面代码保存为.Frm 就可以使用了
VERSION 5.00
Begin VB.Form Form1
Caption = "蒙提霍尔问题/三门问题;qq:1457070900"
ClientHeight = 3795 <

br /> 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)
三门问题(Monty Hall problem)_法律资料_人文社科_专业资料。三門問題——亦稱為蒙提霍爾問題、蒙特霍問題或蒙提霍爾悖論(Monty Hall problem) 什麼是三門問題三...
对策理论的实际应用
称为蒙提霍尔问题蒙特霍问题或蒙 提霍尔悖论、三门问题(Monty Hall problem)...因 为三种情况中有两种是透过转换选择而赢的,所以透过转换 选择而赢的概率是 ...
概率论论文
直觉与概率论摘要:大二概率论课程结束了,在一学期的学习过程中,我们掌握了很多...三 三门问题 三门问题( Monty Hall problem )亦称为蒙提霍尔问题蒙特霍问题...
概率知识在实际生活中的应用
3.3 “三门问题三门问题(Monty Hall problem)亦称为蒙提霍尔问题蒙特霍问题或蒙提 霍尔悖论,大致出自美国的电视游戏节目 Let's Make a Deal.问题名字来自...
概率论实验报告正式提交版(一)
著名概率论问题 【问题背景描述】 蒙特霍尔问题,亦称为蒙特霍问题三门问题(英文: MontyHallProblem),是一个源自博弈论的数学游戏问题,出自美国电 视游戏节目...
古典概型学案(二)
整除的概率 四、 课后反思 附录:三门问题三门问题——亦称为蒙提霍尔问题蒙特霍问题或蒙提霍尔悖论(Monty Hall problem) 三门问题(Monty Hall problem) ,是一...
毕业论文·抽奖活动中的概率问题
这便是概率问题上的一 个著名难题——蒙特难题(Monty Hall problem)。 1.2 ...选手在三扇门中任选一扇门是一个古典型概 1 1 率问题, 每个选择并且中奖的...
统计科普
正态分布有极其广泛的实际背景, 生产与科学实验中很多随机变量的概率分布都可以...蒙提霍尔问题,亦称为蒙特霍问题三门问题 这个游戏的玩法是:参赛者会看见三扇...
金融
谁成为倒霉蛋的概率一样, 所以换与不换都一样 ___ 没有看懂你的意思:(关注...经典的蒙提霍尔问题, 亦称为蒙特霍问题三门问题 (Monty Hall Problem) ,是...
更多相关标签:
蒙提霍尔问题 | 蒙提霍尔悖论 | 蒙提霍尔 | 蒙提霍尔三门问题 | 蒙提霍尔问题的应用 | 蒙提霍尔问题证明 | 蒙特卡洛模拟蒙提霍尔 | 蒙提霍尔定律 |