#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define TRUE 1
#define FALSE 0
int main() {
double a, b, s, shinchi;
int count, m, n;
// 真の面積の値 (4つの単位円で囲まれた部分)
shinchi = M_PI - 2.0;
// 試行回数nの増加
for (n = 10; n < 100000; n = n * 5) {
count = 0;
s = 0.0;
// n回の試行
for (m = 0; m < n; m++) {
int inside = TRUE; // すべての条件を満たしたかどうかのフラグ
// 12個の乱数を生成して判定
int i; // ループカウンタの変数をここで宣言
for (i = 0; i < 12; i++) {
a
= (double)rand() / RAND_MAX
; b
= (double)rand() / RAND_MAX
;
// 点 (a, b) がいずれかの円の外ならフラグを下げる
if (!((a * a + b * b <= 1.0) &&
((a - 1) * (a - 1) + b * b <= 1.0) &&
(a * a + (b - 1) * (b - 1) <= 1.0) &&
((a - 1) * (a - 1) + (b - 1) * (b - 1) <= 1.0))) {
inside = FALSE;
break; // 一つでも条件を満たさなければ終了
}
}
if (inside) s += 1.0; // 12個の乱数全てが条件を満たした場合のみカウント
count++;
}
// 面積の推定値
s /= count;
// 誤差の出力
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPG1hdGguaD4KCiNkZWZpbmUgVFJVRSAxCiNkZWZpbmUgRkFMU0UgMAoKaW50IG1haW4oKSB7CiAgICBkb3VibGUgYSwgYiwgcywgc2hpbmNoaTsKICAgIGludCBjb3VudCwgbSwgbjsKCiAgICAvLyDnnJ/jga7pnaLnqY3jga7lgKQgKDTjgaTjga7ljZjkvY3lhobjgaflm7Ljgb7jgozjgZ/pg6jliIYpCiAgICBzaGluY2hpID0gTV9QSSAtIDIuMDsKCiAgICAvLyDoqabooYzlm57mlbBu44Gu5aKX5YqgCiAgICBmb3IgKG4gPSAxMDsgbiA8IDEwMDAwMDsgbiA9IG4gKiA1KSB7CiAgICAgICAgY291bnQgPSAwOwogICAgICAgIHMgPSAwLjA7CgogICAgICAgIC8vIG7lm57jga7oqabooYwKICAgICAgICBmb3IgKG0gPSAwOyBtIDwgbjsgbSsrKSB7CiAgICAgICAgICAgIGludCBpbnNpZGUgPSBUUlVFOyAgLy8g44GZ44G544Gm44Gu5p2h5Lu244KS5rqA44Gf44GX44Gf44GL44Gp44GG44GL44Gu44OV44Op44KwCgogICAgICAgICAgICAvLyAxMuWAi+OBruS5seaVsOOCkueUn+aIkOOBl+OBpuWIpOWumgogICAgICAgICAgICBpbnQgaTsgIC8vIOODq+ODvOODl+OCq+OCpuODs+OCv+OBruWkieaVsOOCkuOBk+OBk+OBp+Wuo+iogAogICAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgMTI7IGkrKykgewogICAgICAgICAgICAgICAgYSA9IChkb3VibGUpcmFuZCgpIC8gUkFORF9NQVg7CiAgICAgICAgICAgICAgICBiID0gKGRvdWJsZSlyYW5kKCkgLyBSQU5EX01BWDsKCiAgICAgICAgICAgICAgICAvLyDngrkgKGEsIGIpIOOBjOOBhOOBmuOCjOOBi+OBruWGhuOBruWkluOBquOCieODleODqeOCsOOCkuS4i+OBkuOCiwogICAgICAgICAgICAgICAgaWYgKCEoKGEgKiBhICsgYiAqIGIgPD0gMS4wKSAmJgogICAgICAgICAgICAgICAgICAgICAgKChhIC0gMSkgKiAoYSAtIDEpICsgYiAqIGIgPD0gMS4wKSAmJgogICAgICAgICAgICAgICAgICAgICAgKGEgKiBhICsgKGIgLSAxKSAqIChiIC0gMSkgPD0gMS4wKSAmJgogICAgICAgICAgICAgICAgICAgICAgKChhIC0gMSkgKiAoYSAtIDEpICsgKGIgLSAxKSAqIChiIC0gMSkgPD0gMS4wKSkpIHsKICAgICAgICAgICAgICAgICAgICBpbnNpZGUgPSBGQUxTRTsKICAgICAgICAgICAgICAgICAgICBicmVhazsgIC8vIOS4gOOBpOOBp+OCguadoeS7tuOCkua6gOOBn+OBleOBquOBkeOCjOOBsOe1guS6hgogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CgogICAgICAgICAgICBpZiAoaW5zaWRlKSBzICs9IDEuMDsgIC8vIDEy5YCL44Gu5Lmx5pWw5YWo44Gm44GM5p2h5Lu244KS5rqA44Gf44GX44Gf5aC05ZCI44Gu44G/44Kr44Km44Oz44OICiAgICAgICAgICAgIGNvdW50Kys7CiAgICAgICAgfQoKICAgICAgICAvLyDpnaLnqY3jga7mjqjlrprlgKQKICAgICAgICBzIC89IGNvdW50OwoKICAgICAgICAvLyDoqqTlt67jga7lh7rlipsKICAgICAgICBwcmludGYoIiVkXHQlZlxuIiwgbiwgZmFicyhzIC0gc2hpbmNoaSkpOwogICAgfQoKICAgIHJldHVybiAwOwp9Cg==