double getResult()
{
int m = 0;
int n = MAX_ITERS;
srand(time(NULL));
for(int i = 0; i < n; i++)
{
Point t = getPoint();
double res = t.x * t.y;
if(res <= 1.0)
m++;
}
return pow(2.0, 1.0 * n / m);
}
int main()
{
for(int i = 0; i < 20; i++)
cout << fixed << setprecision(6) << getResult() << endl;
return 0;
}
观察一下运行结果,效果还是不错的。如下图