Created
July 6, 2018 04:19
-
-
Save aximov/5a0e7ca52d518fbbad44d81bfa6c644a to your computer and use it in GitHub Desktop.
モンテカルロ積分 (MCMCではない)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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