Skip to content

Instantly share code, notes, and snippets.

@aximov
Created July 6, 2018 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aximov/5a0e7ca52d518fbbad44d81bfa6c644a to your computer and use it in GitHub Desktop.
Save aximov/5a0e7ca52d518fbbad44d81bfa6c644a to your computer and use it in GitHub Desktop.
モンテカルロ積分 (MCMCではない)
#include <bits/stdc++.h>
using namespace std;
int main() {
int seed;
seed = 1533627;
srand48(seed);
double x, y, z;
int cnt;
int n = 10000;
for (int i = 0; i < n; ++i) {
x = drand48();
y = drand48();
z = drand48();
if (x*x + y*y + z*z < 1) ++cnt;
}
cout << 8*(double)cnt/(double)n << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment