Advertisement
tiom4eg

RobotSimulate

Apr 22nd, 2022
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. // tiom4eg's precompiler options
  3. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  4. // IO settings
  5. #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
  6. // Quick types
  7. #define ll long long
  8. #define ld double
  9. #define ull unsigned long long
  10. #define pii pair <int, int>
  11. #define pll pair <ll, ll>
  12. #define vi vector <int>
  13. #define mi vector <vector <int> >
  14. // Quick functions
  15. #define endl "\n"
  16. #define F first
  17. #define S second
  18. #define all(a) a.begin(), a.end()
  19. #define sz(a) a.size()
  20. #define pb push_back
  21. #define mp make_pair
  22. #define min(a, b) ((a < b) ? (a) : (b))
  23. #define max(a, b) ((a > b) ? (a) : (b))
  24. // Quick fors
  25. #define FOR(i, a, b) for (int i = a; i < b; ++i)
  26. #define RFOR(i, a, b) for (int i = a; i >= b; --i)
  27. // Pragmas
  28. #pragma GCC optimize("O3,unroll-loops") // let the chaos begin!
  29. #pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt,tune=native")
  30. #pragma GCC comment(linker, "/stack:200000000")
  31. // PBDS
  32. #include <ext/pb_ds/assoc_container.hpp>
  33. #include <ext/pb_ds/tree_policy.hpp>
  34. #define ordered_set tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
  35. #define ook order_of_key
  36. #define fbo find_by_order
  37. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  38. using namespace std;
  39. using namespace __gnu_pbds;
  40. mt19937 rd(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
  41.  
  42. int rng(int n) { return rd() % n + 1; } // [1; n]
  43.  
  44. // Simulation settings
  45. const int ITER = 66666, GEN = 1000;
  46. const int U = 25, D = 25, L = 25, R = 25; // 25%
  47. // Statistics
  48. double dist = 0.0;
  49.  
  50. void sim() {
  51.     int x = 0, y = 0;
  52.     FOR(i, 0, ITER) {
  53.         int cv = rng(U + D + L + R);
  54.         if (cv <= U) y += 1;
  55.         else if (cv <= U + D) y -= 1;
  56.         else if (cv <= U + D + L) x -= 1;
  57.         else x += 1;
  58.     }
  59.     dist += sqrt(x * x + y * y);
  60. }
  61.  
  62. int main() {
  63.     cout << fixed << setprecision(6);
  64.     cout << "simulating " << GEN << " generations with " << ITER << " iterations each" << endl;
  65.     FOR(i, 0, GEN) sim();
  66.     cout << "done" << endl;
  67.     cout << "avg dist: " << dist / (double)GEN;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement