Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using uint = unsigned int;
- using ld = long double;
- const uint INF = ~0;
- const ld eps = 1e-9;
- uint Rand () {
- mt19937_64 rnd(random_device{}());
- return rnd();
- }
- ld rand_x () {
- ld x = Rand();
- x = x * 2 / INF;
- return x;
- }
- ld rand_theta () {
- ld theta = Rand();
- theta = theta / INF * acos(0);
- return theta;
- }
- int main () {
- int step = 100000;
- int cnt = 0;
- for (int i = 1; i <= step; i ++) {
- ld x = rand_x();
- ld theta = rand_theta();
- // cout << x << ' ' << theta << ' ' << x + sin(theta) << endl;
- if (x + sin(theta) - 2.0 > eps) cnt ++;
- }
- ld pi = (ld)step / cnt;
- cout << fixed << setprecision(9) << pi << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement