Advertisement
wym1111

Untitled

Jun 3rd, 2024
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using uint = unsigned int;
  5. using ld = long double;
  6. const uint INF = ~0;
  7. const ld eps = 1e-9;
  8.  
  9. uint Rand () {
  10. mt19937_64 rnd(random_device{}());
  11. return rnd();
  12. }
  13. ld rand_x () {
  14. ld x = Rand();
  15. x = x * 2 / INF;
  16. return x;
  17. }
  18. ld rand_theta () {
  19. ld theta = Rand();
  20. theta = theta / INF * acos(0);
  21. return theta;
  22. }
  23.  
  24. int main () {
  25. int step = 100000;
  26. int cnt = 0;
  27. for (int i = 1; i <= step; i ++) {
  28. ld x = rand_x();
  29. ld theta = rand_theta();
  30. // cout << x << ' ' << theta << ' ' << x + sin(theta) << endl;
  31. if (x + sin(theta) - 2.0 > eps) cnt ++;
  32. }
  33. ld pi = (ld)step / cnt;
  34. cout << fixed << setprecision(9) << pi << endl;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement