先放好第K大的煎饼,然后放好k-1大的煎饼。
因为如果要放对第k-1大的煎饼的位置,所有被变更位置的煎饼一定在区间[1,k-1]内,不会影响到刚才放好的第k大煎饼。
/**==========================================
* This is a solution for ACM/ICPC problem
*
* @source£º
* @type:
* @author: wust_ysk
* @blog: http://blog.csdn.net/yskyskyer123
* @email: 2530094312@qq.com
*===========================================*/
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<sstream>
using namespace std;
typedef long long ll;
const int INF =0x3f3f3f3f;
const int maxn=30 ;
int n,cnt;
struct A
{
int num;
bool operator<(const A y)const
{
return num<y.num;
}
}a[maxn+5],b[maxn+5];
int pos;
string s;
void print(int x)
{
if(cnt++) putchar(' ');
printf("%d",n+1-x);
}
void get(int k)
{
if(pos==k) return ;
if(pos==1)
{
print(k);
reverse(a+1,a+k+1);
return;
}
print(pos);
reverse(a+1,a+pos+1);
print(k);
reverse(a+1,a+k+1);
}
void work()
{
memcpy(b,a,sizeof a);
sort(b+1,b+1+n);
for(int i=n;i>=1;i--)
{
int maxi=-1;
for(int j=1;j<=i;j++)
{
if(a[j].num>maxi)
{
maxi=a[j].num;
pos=j;
}
}
get(i);
}
print(n+1-0);
putchar('\n');
}
int main()
{
while(getline(cin,s))
{
n=0;
cnt=0;
stringstream ss(s);
while(ss>>a[++n].num)
{
if(n!=1) putchar(' ');
printf("%d",a[n].num);
}
putchar('\n');
n--;
work();
}
return 0;
}