Assuming that the number 1~i-1 has been fully normalized, the number I to nth is an unordered interval.
If I is in the first half of the unordered interval, then I will be changed directly to the I position.
Otherwise I will be changed to the first half of the disordered interval, then I will be returned to the position. This allows the maximum number of operations to be returned two times per digit.
1#include <bits/stdc++.h>2 using namespacestd;3 4 Const intMAXN =10000+Ten;5 intA[MAXN];6vector<pair<int,int> >ans;7 8 voidOpintLintR)9 {TenAns.push_back (Make_pair (L,2*r-l-1)); One intt = R-L; A for(inti = L; i < R; i++) Swap (A[i], a[i+T]); - } - the intMain () - { - //freopen ("In.txt", "R", stdin); - + intT scanf"%d", &T); - while(t--) + { A intN scanf"%d", &n); at for(inti =1; I <= N; i++) scanf ("%d", &a[i]); - ans.clear (); - for(inti =1; I < n; i++) - { - if(A[i] = = i)Continue; - intJ; in for(j = i+1; J <= N; J + +)if(A[j] = = i) Break; - if(J-i <= N-j +1) op (i, j); to Else + { - intT = (n-i +1) /2; theOP (n2*t+1, n-t+1); *i--; $ }Panax Notoginseng } - intSZ =ans.size (); theprintf"%d\n", SZ); + for(inti =0; I < sz; i++) printf ("%d%d\n", Ans[i].first, ans[i].second); A } the + return 0; -}
code June
UVa 1611 (sequencing simulation) Crane