#include <iostream>
#include <random>
#include <chrono>
double monte_carlo_simulation(int iterations) {
std::default_random_engine generator;
std::uniform_real_distribution<double> distribution(0.0, 1.0);
int inside_circle = 0;
for (int i = 0; i < iterations; ++i) {
double x = distribution(generator);
double y = distribution(generator);
if (x * x + y * y <= 1) {
++inside_circle;
}
}
return 4.0 * inside_circle / iterations;
}
int main() {
int iterations = 1000000;
auto start = std::chrono::high_resolution_clock::now();
double pi_estimate = monte_carlo_simulation(iterations);
auto end = std::chrono::high_resolution_clock::now();
std::cout << "EstimaciĆ³n de Pi: " << pi_estimate << "\n";
std::cout << "Tiempo de ejecuciĆ³n: "
<< std::chrono::duration<double>(end - start).count() << " segundos\n";
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8cmFuZG9tPgojaW5jbHVkZSA8Y2hyb25vPgoKZG91YmxlIG1vbnRlX2NhcmxvX3NpbXVsYXRpb24oaW50IGl0ZXJhdGlvbnMpIHsKICAgIHN0ZDo6ZGVmYXVsdF9yYW5kb21fZW5naW5lIGdlbmVyYXRvcjsKICAgIHN0ZDo6dW5pZm9ybV9yZWFsX2Rpc3RyaWJ1dGlvbjxkb3VibGU+IGRpc3RyaWJ1dGlvbigwLjAsIDEuMCk7CgogICAgaW50IGluc2lkZV9jaXJjbGUgPSAwOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBpdGVyYXRpb25zOyArK2kpIHsKICAgICAgICBkb3VibGUgeCA9IGRpc3RyaWJ1dGlvbihnZW5lcmF0b3IpOwogICAgICAgIGRvdWJsZSB5ID0gZGlzdHJpYnV0aW9uKGdlbmVyYXRvcik7CiAgICAgICAgaWYgKHggKiB4ICsgeSAqIHkgPD0gMSkgewogICAgICAgICAgICArK2luc2lkZV9jaXJjbGU7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIDQuMCAqIGluc2lkZV9jaXJjbGUgLyBpdGVyYXRpb25zOwp9CgppbnQgbWFpbigpIHsKICAgIGludCBpdGVyYXRpb25z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