Skip to content

Instantly share code, notes, and snippets.

@aximov aximov/MC.cc
Created Jul 6, 2018

Embed
What would you like to do?
モンテカルロ積分 (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
You can’t perform that action at this time.