Subject address: Ultraviolet A 120
Question. Shift from the largest start, and each time the big one is first moved to the top and then to the bottom.
The Code is as follows:
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;int a[500], b[500], d[500];int main(){ int i, j, flag, cnt, n, x, m; while(scanf("%d",&a[0])!=EOF) { b[a[0]]=0; d[0]=a[0]; i=1; cnt=0; while(getchar()!='\n') { scanf("%d",&a[i]); d[i]=a[i]; b[a[i]]=i; i++; } n=i; m=n; for(i=0; i<n; i++) { printf("%d",a[i]); if(i!=n-1) printf(" "); } printf("\n"); sort(d,d+n); while(n--) { if(b[d[n]]==n) continue ; if(b[d[n]]!=0) { x=b[d[n]]; printf("%d ",m-x); for(i=0; i<=x; i++) { b[a[i]]=x-b[a[i]]; } for(i=0; i<=x/2; i++) { int t=a[i]; a[i]=a[x-i]; a[x-i]=t; } } for(i=0; i<=n; i++) { b[a[i]]=n-b[a[i]]; } for(i=0; i<=n/2; i++) { int t=a[i]; a[i]=a[n-i]; a[n-i]=t; } printf("%d ",m-n); } printf("0\n"); } return 0;}
(White Book Training Program) ultraviolet A 120 stacks of flapjacks (constructor)