比赛 |
20091103 |
评测结果 |
AAWWWWWAWWA |
题目名称 |
乳草的入侵 |
最终得分 |
36 |
用户昵称 |
ReimBurSe. |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2009-11-03 11:54:38 |
显示代码纯文本
Program milkweed;
Type
sc=array [1..100,1..100] of longint;
Var
i,j:longint;
s,shizi:sc;
x,y:longint;
m,n,t:longint;
c:char;
o,o1,o2:boolean;
Begin
assign(input,'milkweed.in');
assign(output,'milkweed.out');
reset(input);
rewrite(output);
readln(n,m,x,y);
for i:=1 to m do
for j:=1 to n do
s[i,j]:=-2;
for i:=1 to m do begin
for j:=1 to n do begin
read(c);
if c='*' then s[i,j]:=-1;
end;
readln;
end;
x:=m-x+1;
s[x,y]:=0;
o:=true;
t:=0;
while o=true do begin
t:=t+1;
o1:=false;
for i:=1 to m do begin
for j:=1 to n do begin
if s[i,j]=t-1 then begin
if j-1>=1 then begin
if s[i,j-1]=-2 then begin
s[i,j-1]:=t;
o1:=true;
end;
end;
if j+1<=n then begin
if s[i,j+1]=-2 then begin
s[i,j+1]:=t;
o1:=true;
end;
end;
if (i-1)>=1 then begin
if s[i-1,j]=-2 then begin
s[i-1,j]:=t;
o1:=true;
end;
if j-1>=1 then begin
if s[i-1,j-1]=-2 then begin
s[i-1,j-1]:=t;
o1:=true;
end;
end;
if j+1<=n then begin
if s[i-1,j+1]=-2 then begin
s[i-1,j+1]:=t;
o1:=true;
end;
end;
end;
if (i+1)<=n then begin
if s[i+1,j]=-2 then begin
s[i+1,j]:=t;
o1:=true;
end;
if j-1>=1 then begin
if s[i+1,j-1]=-2 then begin
s[i+1,j-1]:=t;
o1:=true;
end;
end;
if j+1<=n then begin
if s[i+1,j+1]=-2 then begin
s[i+1,j+1]:=t;
o1:=true;
end;
end;
end;
end;
end;
end;
o2:=true;
for i:=1 to m do
for j:=1 to n do
if s[i,j]=-2 then o2:=false;
if o2=true then o:=false;
if (o1=false)and(o=true) then begin
writeln('-1');
close(input);
close(output);
halt;
end;
end;
writeln(t);
close(input);
close(output);
End.