这种情况下你会改变你的选择吗? (有意思的概率问题)
有三间屋子,A、B、C,一件礼物a,这件礼物被放到了三间屋子中的一个,现在让你来猜礼物在哪间屋子里。
很明显,随便猜一个,猜中的概率为1/3,这个很简单,但接下来的问题是:
如果你选择的屋子是X,在放礼物的人知情的情况下,他打开了一间屋子,这间屋子:
- 不是你所选择的屋子X
- 不是包含礼物的屋子Y
问,剩下两间屋子中,X和另一间屋子Z中有礼物的概率如何?
答案并不是显而易见的……
这是我写的一段验证代码:
#include <cstdlib>
#include <iostream>
using namespace std;
/*
* Obtain time for seed. This program does not need high quality randomness
*/
#include <time.h>
int main()
{
int giftRoom, myChoice, hisChoice;
int nCorrect, nWrong;
nCorrect = nWrong = 0;
srand((unsigned)time(NULL));
for(int i=0; i<1000000; i++){
// Obtain the location of the object
giftRoom = rand() % 3;
// You have chosen a room from the three, this is independent.
myChoice = rand() % 3;
/*
* Now that we have a 1/3 possiblity of obtaining the gift
* in the room. However, this will be soon changed!
*
* Look for a room which is not what you have chosen, and
* it does not contain the gift.
*/
do {
hisChoice = rand() % 3;
}while((hisChoice!=myChoice) && (hisChoice != giftRoom));
if(myChoice == giftRoom){
nCorrect += 1;
} else {
nWrong +=1;
}
}
cout << nCorrect << "," << nWrong << endl;
cin.ignore();
return 0;
}
诡异的是,X和Z中有礼物的概率是1:2,换言之,如果改变选择,那么,有2/3的可能是对的,反之,则只有1/3。
据说这个问题有相当严格的数学证明,然而目前为止我还没有找到。