本帖最后由 蜘蛛抱蛋 于 2010-11-26 12:35 编辑
问题很简单,某某节目上,一嘉宾猜测某奖品价格,规定次数内猜中就可以把奖品抱回家。如何才能使胜率最大?
下面是两种方法比:$p = InputBox("真实", "输入整数", "640", " M3")
$t = InputBox("价格区间", "输入两个整数作为最初的价格范围,用空格间隔开", "0 800")
$price = StringSplit($t, Chr(32), 2)
Dim $i = 0,$try = 0,$try2 = 0
While $try <> $p ;每次取平均值
$i += 1
If BitAND($price[0]+$price[1], 1) = 1 Then
$try = Int(($price[0] + $price[1])/2)+Random(0,1,1)
Else
$try = Int(($price[0] + $price[1])/2)
EndIf
ConsoleWrite($try & Chr(32))
If $try>$p Then
ConsoleWrite("高了" & @CRLF)
$price[1] = $try
EndIf
If $try<$p Then
ConsoleWrite("低了" & @CRLF)
$price[0] = $try
EndIf
WEnd
MsgBox(0,"答对了","共猜" & $i & "次")
While $try2 <> $p ;完全随机
$i += 1
$try2 = Random($price[0], $price[1], 1)
ConsoleWrite($try2 & Chr(32))
If $try2>$p Then
ConsoleWrite("高了" & @CRLF)
$price[1] = $try2
EndIf
If $try2<$p Then
ConsoleWrite("低了" & @CRLF)
$price[0] = $try2
EndIf
WEnd
MsgBox(0,"答对了","共猜" & $i & "次")
问题变化一下,猜价格改为抽奖,只有两次机会,第一次猜完,主持人从剩余的箱子去掉一个错误答案。此时,你可以选择换一个猜,或者不换。那么得奖的概率是否有所不同?
|