题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18284
/*
solution:
先排序,然后从后往前扫,如果不是排序后的位置,则往前找,找到了,如果不是在0位置,那么,把它先翻到0位置,然后再翻回来
note:
构造法
date:
2016/5/18
*/
#include <iostream>
#include <cstdio>
#include <sstream>
#include <algorithm>
using namespace std;
const int maxn = 30 + 5;
int a[maxn], n;
void flip(int p) {
for(int i = 0; i * 2 < p; i++)
swap(a[i], a[p-i]);
printf("%d ", n - p);
}
int main() {
string s;
while(getline(cin, s)) {
cout << s << "\n";
stringstream ss(s);
n = 0;
while(ss >> a[n]) n++;
for(int i = n - 1; i > 0; i--) {
int p = max_element(a, a + i + 1) - a;
if(p == i) continue;
if(p > 0) flip(p);
flip(i);
}
printf("0\n");
}
}