讨论 / 其实都一样
唯梦飞翔 2011-10-18 19:16:00
点我顶贴 收藏 删除
var n,m,i,s,min,j,l:longint;

a:array[0..10000] of longint;

procedure swap(var i,j:longint);

var t:longint;

begin

t:=i;i:=j;j:=t;

end;

procedure solve(x,y:longint);

var xx,yy,i:longint;

begin

swap(a[x],a[y]);

for i:=1 to (x+n) div 2-x do

begin

xx:=x+i;

yy:=n-i+1;

swap(a[xx],a[yy]);

end;

end;

procedure search(n:longint);

var s,i,j,l,min:longint;

begin

s:=0;

while s<>m do

begin

min:=maxlongint;

for i:=n-1 downto 1 do

if a[i]<a[i+1] then

begin

for j:=i+1 to n do

if (a[j]>a[i]) and (a[j]<min) then

begin

min:=a[j];

l:=j;

end;

if min<>maxlongint then break;

end;

solve(i,l);inc(s);

end;

end;

procedure print(n:longint);

begin

for i:=1 to n-1 do write(a[i],' ');writeln(a[n]);

end;

begin

readln(n);

readln(m);

for i:=1 to n do read(a[i]);

search(n);

print(n);

end.

查看更多回复
提交回复