记录编号 |
8061 |
评测结果 |
AAAAWAEEAA |
题目名称 |
移动骷髅 |
最终得分 |
70 |
用户昵称 |
辨机ZN |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
0.351 s |
提交时间 |
2008-11-12 19:44:32 |
内存使用 |
99.29 MiB |
显示代码纯文本
program ex(f1,f2);
type
zn=array [1..2000000] of string[25];
var
a:zn; f1,f2:text; i,j,k,p,m,n,l:longint; ch:char;
tree:zn; head,tail,wei,tot:longint; flag:boolean;
now,s:string[25];
procedure init;
begin
assign(f1,'klgame.in'); reset(f1);
assign(f2,'klgame.out'); rewrite(f2);
readln(f1,n);
end;
procedure swap(var s1,s2:char);
var
k:char;
begin
k:=s1; s1:=s2; s2:=k;
end;
procedure insert(s:string[25]);
var
i,j,k,p:longint; flag:boolean;
begin
p:=1; flag:=true;
while flag do
begin
if tree[p]='' then begin tree[p]:=s; exit; end;
if tree[p]=s then begin dec(wei); exit; end;
if s<tree[p] then p:=p*2 else p:=p*2+1;
end;
end;
procedure bfs(x:longint);
var
i,j,k,left,right:integer;
begin
for i:=1 to 25 do
if a[x][i]<>'0' then
begin
case i of
1..5:begin left:=1; right:=5; end;
6..10:begin left:=6; right:=10; end;
11..15:begin left:=11; right:=15; end;
16..20:begin left:=16; right:=20; end;
21..25:begin left:=21; right:=25; end;
end;
for j:=i-2 downto left do if (a[x][j]<>'0')and(a[x][j+1]='0') then
begin
inc(wei);
a[wei]:=a[x];
swap(a[wei][j+1],a[wei][i]);
insert(a[wei]);
if a[wei][13]='2' then begin flag:=false; exit; end;
break;
end;
for j:=i+2 to right do if (a[x][j]<>'0')and(a[x][j-1]='0') then
begin
inc(wei);
a[wei]:=a[x];
swap(a[wei][j-1],a[wei][i]);
insert(a[wei]);
if a[wei][13]='2' then begin flag:=false; exit; end;
break;
end;
k:=2;
while (i+5*k<=25) do
begin
if (a[x][i+5*k]<>'0')and(a[x][i+5]='0') then
begin
inc(wei);
a[wei]:=a[x];
swap(a[wei][i+5*(k-1)],a[wei][i]);
insert(a[wei]);
if a[wei][13]='2' then begin flag:=false; exit; end;
break;
end;
inc(k);
end;
k:=2;
while (i-5*k>=1) do
begin
if (a[x][i-5*k]<>'0')and(a[x][i-5]='0') then
begin
inc(wei);
a[wei]:=a[x];
swap(a[wei][i-5*(k-1)],a[wei][i]);
insert(a[wei]);
if a[wei][13]='2' then begin flag:=false; exit; end;
break;
end;
inc(k);
end;
end;
end;
begin
init;
for l:=1 to n do
begin
for i:=1 to 500000 do tree[i]:='';
now:='';
for i:=1 to 5 do
begin
readln(f1,s);
now:=now+s;
end;
readln(f1);
a[1]:=now;
insert(now);
head:=1; tail:=1; wei:=1; tot:=0;
flag:=true;
while flag do
begin
inc(tot);
for j:=head to tail do bfs(j);
head:=tail+1; tail:=wei;
end;
writeln(f2,'level ',l,':');
writeln(f2,tot);
end;
close(f1);
close(f2);
end.