在三门问题中,需要弄清楚在任何时候,不换选中的概率。
- 在不开门之前,是1/3
- 再开门之后,是多少?
对于开门之后的判断出现偏差是来自于下面的语句,是对于开启的那扇门的选择上的,是一个随机事件,还是一个有目的的事件。显然是后者,因此在程序中,不应该加下面这个判断条件。
if(look==car||look==select)
continue;
- 测试程序如下
#include <iostream>
#include <stdlib.h>
#include <time.h>
#define N 100000
using namespace std;
int main()
{
srand((unsigned)time(NULL));
int count=0;
int count2=0;
for(int i=0;i<N;i++)
{
int select=rand()%3;
int car=rand()%3;
int look=rand()%3;
if(look==car||look==select)
continue;
count2++;
if(select==car)
count++;
}
cout<<(float)count/count2<<endl;
return 0;
}