#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define NUM_POINTS 10000 // 乱数の個数
// 点が円の中にあるかどうかを判定する関数
int is_in_overlap(double x, double y) {
double dist1 = (x - 0.5) * (x - 0.5) + y * y;
double dist2 = (x - 0.5) * (x - 0.5) + (y - 1) * (y - 1);
return (dist1 <= 0.25) && (dist2 <= 0.25);
}
int main() {
int i, count = 0;
double x, y;
double estimated_area;
for (i = 0; i < NUM_POINTS; i++) {
x
= (double)rand() / RAND_MAX
; y
= (double)rand() / RAND_MAX
;
if (is_in_overlap(x, y)) {
count++;
}
}
// 重複領域の面積の推定値
estimated_area = 4.0 * (double)count / NUM_POINTS;
printf("推定される重複領域の面積: %f\n", estimated_area
);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPG1hdGguaD4KI2luY2x1ZGUgPHRpbWUuaD4KCiNkZWZpbmUgTlVNX1BPSU5UUyAxMDAwMCAvLyDkubHmlbDjga7lgIvmlbAKCi8vIOeCueOBjOWGhuOBruS4reOBq+OBguOCi+OBi+OBqeOBhuOBi+OCkuWIpOWumuOBmeOCi+mWouaVsAppbnQgaXNfaW5fb3ZlcmxhcChkb3VibGUgeCwgZG91YmxlIHkpIHsKICAgIGRvdWJsZSBkaXN0MSA9ICh4IC0gMC41KSAqICh4IC0gMC41KSArIHkgKiB5OwogICAgZG91YmxlIGRpc3QyID0gKHggLSAwLjUpICogKHggLSAwLjUpICsgKHkgLSAxKSAqICh5IC0gMSk7CiAgICByZXR1cm4gKGRpc3QxIDw9IDAuMjUpICYmIChkaXN0MiA8PSAwLjI1KTsKfQoKaW50IG1haW4oKSB7CiAgICBpbnQgaSwgY291bnQgPSAwOwogICAgZG91YmxlIHgsIHk7CiAgICBkb3VibGUgZXN0aW1hdGVkX2FyZWE7CgogICAgc3JhbmQodGltZShOVUxMKSk7IC8vIOS5seaVsOOBrueoruOCkuioreWumgoKICAgIGZv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