| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
大模拟啊……看到很多人讨论……有那么难么?纯模拟就行了啊。
我的代码:
Program POJ1833;
Const
maxn=2000;
Var
i,j,k,m,n,s,temp,p,res,rem :Longint;
a :Array[0..maxn]of Longint;
b :Array[0..maxn]of Longint;
Procedure Changedir;
var p,q:Longint;
begin
for p:=m downto 1 do
if a[p]>a[p-1] then begin
rem:=p;
for q:=rem to m do
b[rem+m-q]:=a[q];
for q:=rem to m do
a[q]:=b[q];
exit;
end;
end;
Procedure Main;
begin
readln(n);
for i:=1 to n do
begin
readln(m,k);
s:=0;
for j:=1 to m do
read(a[j]);
while s<k do
begin
inc(s);
for j:=m-1 downto 0 do
if a[j]<a[j+1] then
begin
for p:=j+1 to m+1 do
if a[p]<a[j]then break;
dec(p);
temp:=a[p];a[p]:=a[j];a[j]:=temp;
if a[0]<>0 then
begin
for res:=m downto 1 do
a[res]:=a[res-1];
a[0]:=0;
changedir;
end
else begin
for p:=j+1 to m do
b[m+j+1-p]:=a[p];
for p:=j+1 to m do
a[p]:=b[p];
end;
break;
end;
end;
for j:=1 to m-1 do
write(a[j],' ');
writeln(a[m]);
end;
end;
BEGIN
main;
END.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator