比赛 |
20101224 |
评测结果 |
WWWWWWWWWE |
题目名称 |
激光电话 |
最终得分 |
0 |
用户昵称 |
belong.zmx |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-12-24 20:53:40 |
显示代码纯文本
program lphone(input,output);
var
i,j,k:longint;
a:array[1..100,1..100]of char;
f:array[1..100,1..100,1..4]of boolean;
m,n,l:longint;
x,y,x1,y1:longint;
ans:longint;
procedure tr(x,y,g,h:longint);
var
i,j:longint;
begin
if (x=x1)and(y=y1) then
begin
if g<ans then ans:=g;
end
else
begin
if h=0 then
begin
if (x+1<=n)and(a[x+1,y]<>'*') then
begin
f[x+1,y,2]:=true;
tr(x+1,y,g,2);
end;
if (y+1<=m)and(a[x,y+1]<>'*') then
begin
f[x,y+1,4]:=true;
tr(x,y+1,g,4);
end;
if (x-1>0)and(a[x-1,y]<>'*') then
begin
f[x-1,y,1]:=true;
tr(x-1,y,g,1);
end;
if (y-1>0)and(a[x,y-1]<>'*') then
begin
f[x,y-1,3]:=true;
tr(x,y-1,g,3);
end;
end;
if h=1 then
begin
if (y+1<=m)and(a[x,y+1]<>'*')and(f[x,y+1,4]=false) then
begin
f[x,y+1,4]:=true;
tr(x,y+1,g+1,4);
end;
if (x-1>0)and(a[x-1,y]<>'*')and(f[x-1,y,1]=false) then
begin
f[x-1,y,1]:=true;
tr(x-1,y,g,1);
end;
if (y-1>0)and(a[x,y-1]<>'*')and(f[x,y-1,3]=false) then
begin
f[x,y-1,3]:=true;
tr(x,y-1,g+1,3);
end;
end;
if h=2 then
begin
if (y+1<=m)and(a[x,y+1]<>'*')and(f[x,y+1,4]=false) then
begin
f[x,y+1,4]:=true;
tr(x,y+1,g+1,4);
end;
if (x+1>0)and(a[x+1,y]<>'*')and(f[x+1,y,1]=false) then
begin
f[x+1,y,1]:=true;
tr(x+1,y,g,1);
end;
if (y-1>0)and(a[x,y-1]<>'*')and(f[x,y-1,3]=false) then
begin
f[x,y-1,3]:=true;
tr(x,y-1,g+1,3);
end;
end;
if h=3 then
begin
if (x+1<=m)and(a[x+1,y]<>'*')and(f[x+1,y,4]=false) then
begin
f[x+1,y,4]:=true;
tr(x+1,y,g+1,4);
end;
if (x-1>0)and(a[x-1,y]<>'*')and(f[x-1,y,1]=false) then
begin
f[x-1,y,1]:=true;
tr(x-1,y,g,1);
end;
if (y-1>0)and(a[x,y-1]<>'*')and(f[x,y-1,3]=false) then
begin
f[x,y-1,3]:=true;
tr(x,y-1,g+1,3);
end;
end;
if h=4 then
begin
if (y+1<=m)and(a[x,y+1]<>'*')and(f[x,y+1,4]=false) then
begin
f[x,y+1,4]:=true;
tr(x,y+1,g+1,4);
end;
if (x-1>0)and(a[x-1,y]<>'*')and(f[x-1,y,1]=false) then
begin
f[x-1,y,1]:=true;
tr(x-1,y,g,1);
end;
if (x+1>0)and(a[x+1,y]<>'*')and(f[x+1,y,3]=false) then
begin
f[x+1,y,3]:=true;
tr(x+1,y,g+1,3);
end;
end;
end;
end;
begin
assign(input,'lphone.in');
reset(input);
readln(m,n);
l:=1;
for i:=1 to n do
begin
for j:=1 to m do
begin
read(a[i,j]);
if a[i,j]='C' then
begin
if l=1 then
begin
x:=i;
y:=j;
l:=2;
end;
if l=2 then
begin
x1:=i;
y1:=j;
end;
end;
end;
readln;
end;
close(input);
ans:=maxlongint;
tr(x,y,0,0);
assign(output,'lphone.out');
rewrite(output);
writeln(ans);
close(output);
end.