tyvjp1030 乳草的入侵
P1030 - 乳草的入侵From public Normal (OI) 总时限:10s 内存限制:128MB |
|||||||
|---|---|---|---|---|---|---|---|
|
|||||||
Delphi语言: 高亮代码由发芽网提供
program tyvj1030;
type node=record
x,y,time:longint;
end;
var d:array[1..8] of integer=(1,0,-1,0,1,-1,1,-1);
l:array[1..8] of integer= (0,-1,0,1,-1,1,1,-1);
a:array[0..101,0..101] of longint;
q:array[1..10000] of node;
head,tail,i,j,x,y,mx,my,ans:longint;
k:node;
ch:string;
procedure push(x,y,t:longint);
begin
inc(head);
q[head].x:=x;q[head].y:=y;q[head].time:=t;
end;
function pop:node;
begin
pop:=q[tail];
inc(tail);
end;
begin
fillchar(a,sizeof(a),2);
readln(x,y,mx,my);
for j:=y downto 1 do begin
readln(ch);
for i:=1 to x do
case ch[i] of
'.':a[i,j]:=1;
'*':a[i,j]:=2;
end;
end;
a[mx,my]:=3;
head:=0;tail:=1;
push(mx,my,0);
ans:=0;
while head>=tail do begin
k:=pop;
if k.time>ans then ans:=k.time;
for i:=1 to 8 do
if a[k.x+d[i],k.y+l[i]]=1 then begin
a[k.x+d[i],k.y+l[i]]:=3;
push(k.x+d[i],k.y+l[i],k.time+1);
end;
end;
writeln(ans);
end.
浙公网安备 33010602011771号