比赛 |
20091103 |
评测结果 |
AAWWWWAAWWA |
题目名称 |
乳草的入侵 |
最终得分 |
45 |
用户昵称 |
rottenwood |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2009-11-03 11:41:27 |
显示代码纯文本
program milkweed;
const
xx:array[1..8] of integer=(-1,-1,0,1,1,1,0,-1);
yy:array[1..8] of integer=(0,1,1,1,0,-1,-1,-1);
var
map:array[1..100,1..100] of string;
i,j,k,m,n,x,y,mx,my,tol:longint;
s1:string;
flag:boolean;
procedure floodfill;
var head,tail,i,j,tou,tailte:longint;
a:array[0..10001,1..2] of longint;
begin
fillchar(a,sizeof(a),0);
a[0,1]:=mx; a[0,2]:=my;
head:=0;tail:=0;tol:=-1;
tou:=head;tailte:=tail;
repeat
inc(tol);
tou:=head;
for k:=head to tail do
begin
for i:=1 to 8 do
begin
if (a[k,1]+xx[i]<=x)and(a[k,1]+xx[i]>=1)and
(a[k,2]+yy[i]<=y)and(a[k,2]+yy[i]>=1)
then
if map[a[k,1]+xx[i],a[k,2]+yy[i]]='.' then
begin
map[a[k,1]+xx[i],a[k,2]+yy[i]]:='m';
inc(tailte);
a[tailte,1]:=a[k,1]+xx[i];
a[tailte,2]:=a[k,2]+yy[i];
end;
end;
end;
head:=tail+1;
tail:=tailte;
until head>tail;
end;
begin
assign(input,'milkweed.in');reset(input);
assign(output,'milkweed.out');rewrite(output);
readln(y,x,mx,my);
flag:=true;
for i:=1 to x do
begin
readln(s1);
for j:=1 to y do
map[i,j]:=s1[j];
end;
map[mx,my]:='m';
floodfill;
for i:=1 to x do
for j:=1 to y do
if map[x,y]='.' then flag:=false;
if flag then writeln(tol) else writeln('-1');
close(output);
end.