Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2022
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using ll = long long;
  5.  
  6. void solve(){
  7.   int i, j;
  8.   int n = 6;
  9.   vector<int> ra = {1,1,1,0,0,1};
  10.   int cnt = 1000000;
  11.   ll moves = 0;
  12.   vector<pair<int,int>> pos;
  13.   for(int i = 0; i < n; i++){
  14.     for(j = i+1; j < n; j++){
  15.       pos.push_back({i,j});
  16.     }
  17.   }
  18.   for(int t = 0; t < cnt; t++){
  19.     mt19937 rng(t);
  20.     vector<int> a = ra;
  21.     while(!is_sorted(a.begin(), a.end())){
  22.       pair<int,int> cur = pos[uniform_int_distribution<int>(0,pos.size()-1)(rng)];
  23.       i = cur.first;
  24.       j = cur.second;
  25.       swap(a[i],a[j]);
  26.       moves++;
  27.     }
  28.   }
  29.   long double ans = moves/(long double)cnt;
  30.   cout << ans;
  31. }
  32.  
  33. int main(){
  34.   solve();
  35.   return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement