#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define M_PI 3.14159265
#define NUM_RANDOM 12 // 乱数の個数を12に固定
int main() {
double a[NUM_RANDOM], b[NUM_RANDOM], s, shinchi;
int count, m, n, i;
// 真の値(4つの単位円で囲まれた領域)
shinchi = M_PI - 2.0;
count = 0;
// nの範囲で乱数の試行回数を増やす
for (n = 10; n < 100000; n = n * 5) {
count = 0;
s = 0.0;
for (m = 0; m < n; m++) {
// 12個のランダムな点 (a[i], b[i]) を生成
for (i = 0; i < NUM_RANDOM; i++) {
a
[i
] = (double)rand() / RAND_MAX
; b
[i
] = (double)rand() / RAND_MAX
; }
// 12個の点が4つの円に含まれるかチェック
for (i = 0; i < NUM_RANDOM; i++) {
if ((a[i] * a[i] + b[i] * b[i] <= 1.0) && // (0, 0) を中心とする円
((a[i] - 1) * (a[i] - 1) + b[i] * b[i] <= 1.0) && // (1, 0) を中心とする円
(a[i] * a[i] + (b[i] - 1) * (b[i] - 1) <= 1.0) && // (0, 1) を中心とする円
((a[i] - 1) * (a[i] - 1) + (b[i] - 1) * (b[i] - 1) <= 1.0)) { // (1, 1) を中心とする円
s += 1.0;
}
}
count += NUM_RANDOM; // 12個の点をカウント
}
// 面積の推定値
s /= count;
// 誤差の出力
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPG1hdGguaD4KCiNkZWZpbmUgTV9QSSAzLjE0MTU5MjY1CiNkZWZpbmUgTlVNX1JBTkRPTSAxMiAgLy8g5Lmx5pWw44Gu5YCL5pWw44KSMTLjgavlm7rlrpoKCmludCBtYWluKCkgewogICAgZG91YmxlIGFbTlVNX1JBTkRPTV0sIGJbTlVNX1JBTkRPTV0sIHMsIHNoaW5jaGk7CiAgICBpbnQgY291bnQsIG0sIG4sIGk7CgogICAgLy8g55yf44Gu5YCk77yINOOBpOOBruWNmOS9jeWGhuOBp+WbsuOBvuOCjOOBn+mgmOWfn++8iQogICAgc2hpbmNoaSA9IE1fUEkgLSAyLjA7CgogICAgY291bnQgPSAwOwoKICAgIC8vIG7jga7nr4Tlm7LjgafkubHmlbDjga7oqabooYzlm57mlbDjgpLlopfjgoTjgZkKICAgIGZvciAobiA9IDEwOyBuIDwgMTAwMDAwOyBuID0gbiAqIDUpIHsKICAgICAgICBjb3VudCA9IDA7CiAgICAgICAgcyA9IDAuMDsKCiAgICAgICAgZm9yIChtID0gMDsgbSA8IG47IG0rKykgewogICAgICAgICAgICAvLyAxMuWAi+OBruODqeODs+ODgOODoOOBqueCuSAoYVtpXSwgYltpXSkg44KS55Sf5oiQCiAgICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBOVU1fUkFORE9NOyBpKyspIHsKICAgICAgICAgICAgICAgIGFbaV0gPSAoZG91YmxlKXJhbmQoKSAvIFJBTkRfTUFYOwogICAgICAgICAgICAgICAgYltpXSA9IChkb3VibGUpcmFuZCgpIC8gUkFORF9NQVg7CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIC8vIDEy5YCL44Gu54K544GMNOOBpOOBruWGhuOBq+WQq+OBvuOCjOOCi+OBi+ODgeOCp+ODg+OCrwogICAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgTlVNX1JBTkRPTTsgaSsrKSB7CiAgICAgICAgICAgICAgICBpZiAoKGFbaV0gKiBhW2ldICsgYltpXSAqIGJbaV0gPD0gMS4wKSAmJiAgICAgICAgICAgIC8vICgwLCAwKSDjgpLkuK3lv4PjgajjgZnjgovlhoYKICAgICAgICAgICAgICAgICAgICAoKGFbaV0gLSAxKSAqIChhW2ldIC0gMSkgKyBiW2ldICogYltpXSA8PSAxLjApICYmIC8vICgxLCAwKSDjgpLkuK3lv4PjgajjgZnjgovlhoYKICAgICAgICAgICAgICAgICAgICAoYVtpXSAqIGFbaV0gKyAoYltpXSAtIDEpICogKGJbaV0gLSAxKSA8PSAxLjApICYmIC8vICgwLCAxKSDjgpLkuK3lv4PjgajjgZnjgovlhoYKICAgICAgICAgICAgICAgICAgICAoKGFbaV0gLSAxKSAqIChhW2ldIC0gMSkgKyAoYltpXSAtIDEpICogKGJbaV0gLSAxKSA8PSAxLjApKSB7IC8vICgxLCAxKSDjgpLkuK3lv4PjgajjgZnjgovlhoYKICAgICAgICAgICAgICAgICAgICBzICs9IDEuMDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBjb3VudCArPSBOVU1fUkFORE9NOyAgLy8gMTLlgIvjga7ngrnjgpLjgqvjgqbjg7Pjg4gKICAgICAgICB9CgogICAgICAgIC8vIOmdouepjeOBruaOqOWumuWApAogICAgICAgIHMgLz0gY291bnQ7CgogICAgICAgIC8vIOiqpOW3ruOBruWHuuWKmwogICAgICAgIHByaW50ZigiJWRcdCVmXG4iLCBuLCBmYWJzKHMgLSBzaGluY2hpKSk7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0K