#include <math.h>
#include <stdio.h>
#include <stdlib.h>

void main()                          /* walk on spheres */
{
    const float pi2 = 8.*atan(1.)/RAND_MAX;
    const float a = 10., b = 1., h = 1.e-2; /* geometry */
    const int n = 1e8;             /* number of samples */
    float x,y,r,phi,p;
    int k,count,hit;

    count = 0;
    for (k=0; k<n; k++) {            /* statistics loop */
        x = 0.; y = 0.;
        do {                            /* a single run */
            r = min(min(a-x,a+x),min(b-y,b+y));
            phi = pi2*rand();
            x += r*cos(phi); y += r*sin(phi);
        } while ((fabs(x)<a-h) & (hit=(fabs(y)<b-h)));
        count += hit;
    }
    p = ((float)count)/n;
    printf("%e \n",p);
}

