#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define M_PI 3.14159265
int main() {
double a, b, s, x1, x2, x3, x4, y1, y2, y3, y4;
double r, q1, q2, q3, q4, shinchi;
int count, m, n;
// 理論的な円の面積
shinchi = 1.0;
// 円の中心
x1 = 1.0; y1 = 0.0; // 第一の円の中心
x2 = 0.0; y2 = 1.0; // 第二の円の中心
x3 = 0.0; y3 = 0.0;
x4 = 1.0; y4 = 1.0;
r = 1.0; // 半径
count = 0;
for (n = 10; n < 100000; n = n * 5) {
count = 0;
s = 0.0;
for (m = 0; m < n; m++) {
a
= (double)rand() / RAND_MAX
; // 0.0 から 1.0 の乱数 b
= (double)rand() / RAND_MAX
; // 0.0 から 1.0 の乱数 // 距離の計算
q1 = (a - x1) * (a - x1) + (b - y1) * (b - y1);
q2 = (a - x2) * (a - x2) + (b - y2) * (b - y2);
q3 = (a - x3) * (a - x3) + (b - y3) * (b - y3);
q4 = (a - x4) * (a - x4) + (b - y4) * (b - y4);
count++;
// 両方の円の中に点が入っているかを確認
if (q1 < r && q2 < r && q3 < r && q4 < r) s += 1.0;
}
s /= count; // 平均を取る
printf("%d\t%f\n", n
, fabs(s
- shinchi
)); // 理論値との差を表示 }
return 0;
}
I2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPG1hdGguaD4KIAojZGVmaW5lIE1fUEkgMy4xNDE1OTI2NQogCmludCBtYWluKCkgewogICAgZG91YmxlIGEsIGIsIHMsIHgxLCB4MiwgeDMsIHg0LCB5MSwgeTIsIHkzLCB5NDsKICAgIGRvdWJsZSByLCBxMSwgcTIsIHEzLCBxNCwgc2hpbmNoaTsKICAgIGludCBjb3VudCwgbSwgbjsKIAogICAgLy8g55CG6KuW55qE44Gq5YaG44Gu6Z2i56mNCiAgICBzaGluY2hpID0gMS4wOwogCiAgICAvLyDlhobjga7kuK3lv4MKICAgIHgxID0gMS4wOyB5MSA9IDAuMDsgLy8g56ys5LiA44Gu5YaG44Gu5Lit5b+DCiAgICB4MiA9IDAuMDsgeTIgPSAxLjA7IC8vIOesrOS6jOOBruWGhuOBruS4reW/gwogICAgeDMgPSAwLjA7IHkzID0gMC4wOwogICAgeDQgPSAxLjA7IHk0ID0gMS4wOwogICAgciA9IDEuMDsgLy8g5Y2K5b6ECiAgICBjb3VudCA9IDA7CiAKICAgIGZvciAobiA9IDEwOyBuIDwgMTAwMDAwOyBuID0gbiAqIDUpIHsKICAgICAgICBjb3VudCA9IDA7CiAgICAgICAgcyA9IDAuMDsKICAgICAgICBmb3IgKG0gPSAwOyBtIDwgbjsgbSsrKSB7CiAgICAgICAgICAgIGEgPSAoZG91YmxlKXJhbmQoKSAvIFJBTkRfTUFYOyAvLyAwLjAg44GL44KJIDEuMCDjga7kubHmlbAKICAgICAgICAgICAgYiA9IChkb3VibGUpcmFuZCgpIC8gUkFORF9NQVg7IC8vIDAuMCDjgYvjgokgMS4wIOOBruS5seaVsAogICAgICAgICAgICAvLyDot53pm6Ljga7oqIjnrpcKICAgICAgICAgICAgcTEgPSAoYSAtIHgxKSAqIChhIC0geDEpICsgKGIgLSB5MSkgKiAoYiAtIHkxKTsKICAgICAgICAgICAgcTIgPSAoYSAtIHgyKSAqIChhIC0geDIpICsgKGIgLSB5MikgKiAoYiAtIHkyKTsKICAgICAgICAgICAgcTMgPSAoYSAtIHgzKSAqIChhIC0geDMpICsgKGIgLSB5MykgKiAoYiAtIHkzKTsKICAgICAgICAgICAgcTQgPSAoYSAtIHg0KSAqIChhIC0geDQpICsgKGIgLSB5NCkgKiAoYiAtIHk0KTsKICAgICAgICAgICAgY291bnQrKzsKICAgICAgICAgICAgLy8g5Lih5pa544Gu5YaG44Gu5Lit44Gr54K544GM5YWl44Gj44Gm44GE44KL44GL44KS56K66KqNCiAgICAgICAgICAgIGlmIChxMSA8IHIgJiYgcTIgPCByICYmIHEzIDwgciAmJiBxNCA8IHIpIHMgKz0gMS4wOwogICAgICAgIH0KICAgICAgICBzIC89IGNvdW50OyAvLyDlubPlnYfjgpLlj5bjgosKICAgICAgICBwcmludGYoIiVkXHQlZlxuIiwgbiwgZmFicyhzIC0gc2hpbmNoaSkpOyAvLyDnkIboq5blgKTjgajjga7lt67jgpLooajnpLoKICAgIH0KIAogICAgcmV0dXJuIDA7Cn0=