记录编号 |
22810 |
评测结果 |
AAEEAAAAEA |
题目名称 |
[USACO Jan09] 激光电话 |
最终得分 |
70 |
用户昵称 |
donny |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
0.026 s |
提交时间 |
2010-12-27 19:14:44 |
内存使用 |
0.25 MiB |
显示代码纯文本
program lphone;
type
s=record
x,y:longint;
end;
var
i,j,k,l,m,n,xx,yy,c,d:longint;
xun,huan:longint;
a:array[0..101,0..101]of longint;
b:array[0..100,0..101]of char;
f:array[0..10000]of s;
w:array[0..101,0..101]of boolean;
procedure go(aa,bb:longint);
var
ii,jj,kk:longint;
begin
ii:=f[aa].x;
jj:=f[aa].y;
kk:=a[ii,jj];
case bb of
1:
while (jj>1)and(b[ii,jj-1]<>'*') do
begin
jj:=jj-1;
if (kk+1)<(a[ii,jj]) then
begin
a[ii,jj]:=kk+1;
w[ii,jj]:=true;
inc(j);
f[j].x:=ii;
f[j].y:=jj;
if (b[ii,jj]='C')and(ii<>xx)and(jj<>yy) then
begin
writeln(a[ii,jj]);
close(input);
close(output);
halt;
end;
end;
end;
2:
while (jj<n)and(b[ii,jj+1]<>'*') do
begin
jj:=jj+1;
if (kk+1)<(a[ii,jj]) then
begin
a[ii,jj]:=kk+1;
w[ii,jj]:=true;
inc(j);
f[j].x:=ii;
f[j].y:=jj;
if (b[ii,jj]='C')and(ii<>xx)and(jj<>yy) then
begin
writeln(a[ii,jj]);
close(input);
close(output);
halt;
end;
end;
end;
3:
while (ii>1)and(b[ii-1,jj]<>'*') do
begin
ii:=ii-1;
if (kk+1)<(a[ii,jj]) then
begin
a[ii,jj]:=kk+1;
w[ii,jj]:=true;
inc(j);
f[j].x:=ii;
f[j].y:=jj;
if (b[ii,jj]='C')and(ii<>xx)and(jj<>yy) then
begin
writeln(a[ii,jj]);
close(input);
close(output);
halt;
end;
end;
end;
4:
while (ii<m)and(b[ii+1,jj]<>'*') do
begin
ii:=ii+1;
if (kk+1)<(a[ii,jj]) then
begin
a[ii,jj]:=kk+1;
w[ii,jj]:=true;
inc(j);
f[j].x:=ii;
f[j].y:=jj;
if (b[ii,jj]='C')and(ii<>xx)and(jj<>yy) then
begin
writeln(a[ii,jj]);
close(input);
close(output);
halt;
end;
end;
end;
end;
end;
begin
assign(input,'lphone.in');
reset(input);
assign(output,'lphone.out');
rewrite(output);
readln(n,m);
for i:=1 to m do
begin
for j:=1 to n do
read(b[i,j]);
readln;
end;
for i:=1 to m do
for j:=1 to n do
if b[i,j]='C' then
begin
xx:=i;
yy:=j;
end;
for i:=1 to m do
for j:=1 to n do
a[i,j]:=maxint;
a[xx,yy]:=0;
i:=1;
w[xx,yy]:=true;
f[i].x:=xx;
f[i].y:=yy;
c:=xx;
d:=yy;
j:=1;
while (d>1)and(b[c,d-1]<>'*') do
begin
d:=d-1;
a[c,d]:=0;
w[c,d]:=true;
inc(j);
f[j].x:=c;
f[j].y:=d;
end;
c:=xx;
d:=yy;
while (d<n)and(b[c,d+1]<>'*') do
begin
d:=d+1;
a[c,d]:=0;
w[c,d]:=true;
inc(j);
f[j].x:=c;
f[j].y:=d;
end;
c:=xx;
d:=yy;
while (c>1)and(b[c-1,d]<>'*') do
begin
dec(c);
a[c,d]:=0;
w[c,d]:=true;
inc(j);
f[j].x:=c;
f[j].y:=d;
end;
c:=xx;
d:=yy;
while (c<m)and(b[c+1,d]<>'*') do
begin
inc(c);
a[c,d]:=0;
w[c,d]:=true;
inc(j);
f[j].x:=c;
f[j].y:=d;
end;
repeat
// if w[f[i].x,f[i].y-1]=false then
go(i,1);
// if w[f[i].x,f[i].y+1]=false then
go(i,2);
// if w[f[i].x-1,f[i].y]=false then
go(i,3);
// if w[f[i].x+1,f[i].y]=false then
go(i,4);
inc(i);
{ for xun:=1 to m do
begin
for huan:=1 to n do
write(a[xun,huan]);
writeln;
end; }
until j=n*m;
writeln('0');
close(input);
close(output);
end.