Test instructions: For a 1~n arrangement, 1<=n<=10000, each operation selects a continuous interval of an even length. Swap the first half and the last half, making it into ascending order.
The problem: Each time you move the smallest to the far left, the size of the issue shrinks. Assuming that the current interval is [l,r], it is not difficult to find, as long as the smallest number in the [l,l+ (R+1-L)/2] This interval, must be able to move the smallest number in a single exchange to the L place, otherwise, you must first exchange the smallest number of moving to the above interval.
#include <bits/stdc++.h>using namespacestd;Const intMAXN = 1e4+5;intA[maxn],pos[maxn];inlinevoidExchangeintS1,intS2) { intlen = s2-S1; for(inti = s1, maxi = S1+len; I < Maxi; i++) {Swap (Pos[a[i]],pos[a[i+Len]]); Swap (A[i],a[i+Len]); }}intl[maxn<<1],r[maxn<<1];#defineOut (A, b) \printf ("%d%d\n", A, b)#defineAddans (l,r) l[cnt] = l; r[cnt++] = RintMain () {//freopen ("In.txt", "R", stdin); intT scanf"%d",&T); while(t--){ intN scanf"%d",&N); for(inti =1; I <= N; i++) {scanf ("%d", A +i); Pos[a[i]]=i; } intCNT =0; for(inti =1, TMP = n+1; I < n; i++)if(pos[i]!=i) {if(pos[i]<<1> tmp+i) { intLen = tmp-i; if(len&1) {Addans (i+1, N); Exchange (I+1, i+1+ (len>>1)); }Else{Addans (i,n); Exchange (I,i+ (len>>1)); }} Addans (I, (Pos[i]<<1)-i-1); Exchange (I,pos[i]); } printf ("%d\n", CNT); for(inti =0; I < CNT; i++) {out (l[i],r[i]); } } return 0;}
UVA 1611 Crane Cranes