比赛 |
20120418s |
评测结果 |
AAATTTTTTT |
题目名称 |
排序 |
最终得分 |
30 |
用户昵称 |
wo shi 刘畅 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2012-04-18 10:12:20 |
显示代码纯文本
var
n,h,t,i,k:longint;
a,b:array[0..1000]of longint;
q:array[0..200000,0..50]of longint;
before,c,step:array[0..200000]of longint;
procedure sort(l,r:longint);
var
i,j,x,y:longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
while a[i]<x do inc(i);
while x<a[j] do dec(j);
if i<=j then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
inc(i);
dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
function chong:boolean;
var
i,now,j:longint;
begin
for i:=1 to t-1 do
begin
now:=0;
for j:=1 to n do
if q[i,j]=q[t,j] then inc(now);
if now=n then exit(true);
end;
exit(false);
end;
function ok:boolean;
var
now,i:longint;
begin
now:=0;
for i:=1 to n do
if a[i]=q[t,i] then inc(now);
if now=n then exit(true);
exit(false);
end;
procedure go(k:longint);
begin
if k=1 then exit;
go(before[k]);
write(c[k],' ');
end;
procedure print;
begin
writeln(step[t]);
go(t);
close(input);
close(output);
halt;
end;
begin
assign(input,'sorta.in'); reset(input);
assign(output,'sorta.out'); rewrite(output);
readln(n);
for i:=1 to n do
begin
read(q[1][i]);
a[i]:=q[1][i];
end;
sort(1,n);
h:=1;
t:=1;
if ok then
begin
writeln(0);
close(input);
close(output);
halt;
end;
repeat
for i:=1 to n do b[i]:=q[h][i];
for k:=2 to n do
begin
inc(t);
for i:=1 to k do q[t][i]:=b[k-i+1];
for i:=k+1 to n do q[t][i]:=b[i];
before[t]:=h;
c[t]:=k;
step[t]:=step[h]+1;
if chong then dec(t);
if ok then print;
end;
inc(h);
until h>t;
writeln;
close(input);
close(output);
end.