#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;

    srand(time(NULL)); // 乱数の種を設定

    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;
}
