记录编号 164194 评测结果 AAAAAAAAAA
题目名称 排序 最终得分 100
用户昵称 GravatarAsm.Def 是否通过 通过
代码语言 C++ 运行时间 0.265 s
提交时间 2015-05-29 11:45:22 内存使用 0.29 MiB
显示代码纯文本
/*****************************************************************************/
/******************************Designed By Asm.Def****************************/
/*****************************************************************************/
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <cmath>
#define SetFile(x) (freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout) )
#define FREAD
#define FREADLENTH 5000
#ifdef FREAD
char *fread_ptr = (char*)malloc(FREADLENTH);
#define getc() (*(fread_ptr++))
#else
#define getc() getchar()
#endif
using namespace std;
template<class T>inline void getd(T &x){
	int ch = getc();bool neg = false;
	while(!isdigit(ch) && ch != '-')ch = getc();
	if(ch == '-')neg = true, ch = getc();
	x = ch - '0';
	while(isdigit(ch = getc()))x = x * 10 - '0' + ch;
	if(neg)x = -x;
}
/*******************************************************************************/
const int maxn = 25;
int A[maxn], B[maxn], N, Ans;
int seq[maxn << 1], tmp[maxn << 1], tmp2[maxn << 1];

inline void Reverse(int i){
	for(int j = 0;(j << 1) < i;++j)swap(A[j], A[i-j]);
}

inline int hunger(){
	int i, j, ans = 0, T[maxn];
	memcpy(B, A, sizeof(int) * (N + 1));
	memcpy(T, A, sizeof(int) * (N + 1));
	sort(T, T + N);
	for(i = N-1;i;--i){
		if(*A != T[i]){
			for(j = 1;j < i;++j)if(A[j] == T[i])
				Reverse(j), tmp2[++ans] = j;
		}
		Reverse(i), tmp2[++ans] = i;
	}
	memcpy(A, B, sizeof(int) * (N + 1));
	return ans;
}

inline int H(){
	int ans = 0, i;
	for(i = 1;i < N;++i)if(abs(A[i] - A[i-1]) > 1)++ans;
	return ans;
}

inline void init(){
	getd(N);
	Ans = (N << 1) + 1;
	int i, id[maxn];
	for(i = 0;i < N;++i)getd(A[i]);
	memcpy(tmp, A, sizeof(int) * N);
	sort(tmp, tmp + N);
	id[0] = 0;
	for(i = 1;i < N;++i)id[i] = id[i-1] + (tmp[i] != tmp[i-1]);
	for(i = 0;i < N;++i)A[i] = id[lower_bound(tmp, tmp+N, A[i])-tmp];
	*tmp = N;
}

int lim;
void dfs(int ans, int last){
	int i;
	if(ans == lim){
		for(i = 1;i < N;++i)if(A[i] < A[i-1])return;
		Ans = ans;
		return;
	}
	if(ans + H() > lim)return;
	++ans;
	for(i = 1;i < N && Ans != lim;++i)if(i != last){
		seq[ans] = i;
		Reverse(i);
		dfs(ans, i);
		Reverse(i);
	}
}

int main(){

#ifdef DEBUG
	freopen("test.txt", "r", stdin);
#else
	SetFile(sorta);
#endif
#ifdef FREAD
	fread(fread_ptr, 1, FREADLENTH, stdin);
#endif

	init();
	
	Ans = hunger();
	memcpy(seq, tmp2, sizeof(int) * (Ans + 1));
	int i;
	for(lim = H();lim < Ans;++lim)dfs(0, -1);
	printf("%d\n", Ans);
	for(i = 1;i <= Ans;++i)printf("%d ", seq[i] + 1);

#ifdef DEBUG
	printf("\n%.3lf sec\n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}