Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- void solve(){
- int i, j;
- int n = 6;
- vector<int> ra = {1,1,1,0,0,1};
- int cnt = 1000000;
- ll moves = 0;
- vector<pair<int,int>> pos;
- for(int i = 0; i < n; i++){
- for(j = i+1; j < n; j++){
- pos.push_back({i,j});
- }
- }
- for(int t = 0; t < cnt; t++){
- mt19937 rng(t);
- vector<int> a = ra;
- while(!is_sorted(a.begin(), a.end())){
- pair<int,int> cur = pos[uniform_int_distribution<int>(0,pos.size()-1)(rng)];
- i = cur.first;
- j = cur.second;
- swap(a[i],a[j]);
- moves++;
- }
- }
- long double ans = moves/(long double)cnt;
- cout << ans;
- }
- int main(){
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement