#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define M_PI 3.14159265
int main() {
double a, b, s, x[4], y[4], r, true_value;
int count, m, n;
x[0] = 1.0; y[0] = 0.0;
x[1] = 0.0; y[1] = 1.0;
x[2] = -1.0; y[2] = 0.0;
x[3] = 0.0; y[3] = -1.0;
r = 1.0;
true_value
= (M_PI
- pow(3, 1.5) + 3) / 3.0;
for (n = 10; n < 100000; n *= 5) {
count = 0;
s = 0.0;
for (m = 0; m < n; m++) {
a
= (double)rand() / RAND_MAX
* 2.0 - 1.0; b
= (double)rand() / RAND_MAX
* 2.0 - 1.0;
int in_all_circles = 1;
for (int i = 0; i < 4; i++) {
double dist = (a - x[i]) * (a - x[i]) + (b - y[i]) * (b - y[i]);
if (dist >= r) {
in_all_circles = 0;
break;
}
}
if (in_all_circles) {
s += 1.0;
}
count++;
}
s /= count;
s *= 4.0;
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPG1hdGguaD4KCiNkZWZpbmUgTV9QSSAzLjE0MTU5MjY1CgppbnQgbWFpbigpIHsKICAgIGRvdWJsZSBhLCBiLCBzLCB4WzRdLCB5WzRdLCByLCB0cnVlX3ZhbHVlOwogICAgaW50IGNvdW50LCBtLCBuOwoKICAgIHhbMF0gPSAxLjA7IHlbMF0gPSAwLjA7CiAgICB4WzFdID0gMC4wOyB5WzFdID0gMS4wOwogICAgeFsyXSA9IC0xLjA7IHlbMl0gPSAwLjA7CiAgICB4WzNdID0gMC4wOyB5WzNdID0gLTEuMDsKCiAgICByID0gMS4wOyAgCiAgICB0cnVlX3ZhbHVlID0gKE1fUEkgLSBwb3coMywgMS41KSArIDMpIC8gMy4wOyAgCgogICAgZm9yIChuID0gMTA7IG4gPCAxMDAwMDA7IG4gKj0gNSkgewogICAgICAgIGNvdW50ID0gMDsKICAgICAgICBzID0gMC4wOwoKICAgICAgICBmb3IgKG0gPSAwOyBtIDwgbjsgbSsrKSB7CiAgICAgICAgICAgIGEgPSAoZG91YmxlKXJhbmQoKSAvIFJBTkRfTUFYICogMi4wIC0gMS4wOyAgCiAgICAgICAgICAgIGIgPSAoZG91YmxlKXJhbmQoKSAvIFJBTkRfTUFYICogMi4wIC0gMS4wOyAgCgogICAgICAgICAgICBpbnQgaW5fYWxsX2NpcmNsZXMgPSAxOwogICAgICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IDQ7IGkrKykgewogICAgICAgICAgICAgICAgZG91YmxlIGRpc3QgPSAoYSAtIHhbaV0pICogKGEgLSB4W2ldKSArIChiIC0geVtpXSkgKiAoYiAtIHlbaV0pOwogICAgICAgICAgICAgICAgaWYgKGRpc3QgPj0gcikgewogICAgICAgICAgICAgICAgICAgIGluX2FsbF9jaXJjbGVzID0gMDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQoKICAgICAgICAgICAgaWYgKGluX2FsbF9jaXJjbGVzKSB7CiAgICAgICAgICAgICAgICBzICs9IDEuMDsKICAgICAgICAgICAgfQogICAgICAgICAgICBjb3VudCsrOwogICAgICAgIH0KCiAgICAgICAgcyAvPSBjb3VudDsgIAogICAgICAgIHMgKj0gNC4wOyAgICAKCiAgICAgICAgcHJpbnRmKCIlZFx0JWZcbiIsIG4sIGZhYnMocyAtIHRydWVfdmFsdWUpKTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQ==