记录编号 |
66494 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[USACO Jan09] 激光电话 |
最终得分 |
100 |
用户昵称 |
lmm |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.005 s |
提交时间 |
2013-07-29 17:03:20 |
内存使用 |
0.97 MiB |
显示代码纯文本
program lphone;
const
infile='lphone.in';
outfile='lphone.out';
var
yq,xq:array [1..100000] of longint;
dist:array [0..100,0..100] of longint;
map:array [0..100,0..100] of char;
i,j,head,tail,y,x,sy,sx:longint;
procedure enq(i,j:longint);
begin
yq[tail]:=i;
xq[tail]:=j;
inc(tail);
end;
procedure outq(var i,j:longint);
begin
i:=yq[head];
j:=xq[head];
inc(head);
end;
begin
assign(input,infile);reset(input);
assign(output,outfile);rewrite(output);
readln(x,y);
for i:=1 to y do begin
for j:=1 to x do begin
read(map[i,j]);
dist[i,j]:=maxlongint;
if map[i,j]='C' then begin
sy:=i;
sx:=j;
end;
end;
readln;
end;
head:=1;
tail:=1;
map[sy,sx]:='*';
dist[sy,sx]:=-1;
enq(sy,sx);
while true do begin
outq(sy,sx);
if map[sy,sx]='C' then break;
for i:=sy-1 downto 1 do begin
if map[i,sx]='*' then break;
if (dist[i,sx])=maxlongint then begin
dist[i,sx]:=dist[sy,sx]+1;
enq(i,sx);
end;
end;
for i:=sy+1 to y do begin
if map[i,sx]='*' then break;
if (dist[i,sx])=maxlongint then begin
dist[i,sx]:=dist[sy,sx]+1;
enq(i,sx);
end;
end;
for i:=sx-1 downto 1 do begin
if map[sy,i]='*' then break;
if (dist[sy,i])=maxlongint then begin
dist[sy,i]:=dist[sy,sx]+1;
enq(sy,i);
end;
end;
for i:=sx+1 to x do begin
if map[sy,i]='*' then break;
if (dist[sy,i])=maxlongint then begin
dist[sy,i]:=dist[sy,sx]+1;
enq(sy,i);
end;
end;
end;
writeln(dist[sy,sx]);
close(input);close(output);
end.