|
|

楼主 |
发表于 2011-10-18 19:17
|
显示全部楼层
[原创]一个有趣的概率问题:撞墙问题
|
[这个贴子最后由技术员在 2012/08/08 07:21pm 第 2 次编辑]
// wall.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "math.h"
#include
#include
int main(int argc, char* argv[])
{
int L;
double Step=6.00001;
double StepMax=7.416,StepMin=4.584;
double X,X1,X2,X3,X4,X5;
double P,P1;
int n1=0,n2=0;
for(int i=1;i<100000;i++)
{
L=rand()%500;
X=fmod(L,Step);
P=X/Step;
X1=fmod(L/2,StepMax);
X2=fmod(L/2,StepMin);
X3=fmod(X1+X2,StepMax);
X4=fmod(X1+X2,StepMin);
X5=(X3+X4)/2;
P1=2*X5/(StepMax+StepMin);
if(P>P1)
{
n1++;
}
else
{
n2++;
}
}
printf("n1=%d n2=%d",n1,n2);
return 0;
}
|
|