记录编号 |
139 |
评测结果 |
AAAAAAAAAAAAAAAA |
题目名称 |
[POI 1999] 位图 |
最终得分 |
100 |
用户昵称 |
francis |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.143 s |
提交时间 |
2008-04-26 17:34:23 |
内存使用 |
0.68 MiB |
显示代码纯文本
program bit;
const
max=10000;
var
a:array[1..182,1..182]of longint;
map:array[1..182,1..182]of integer;
d:array[1..50000,1..2]of longint;
z:array[1..4,1..2]of longint;
deep,x1,x2,k,n,m,i,j:longint;
st:string;
f1,f2:text;
procedure init;
begin
assign(f1,'bit.in'); assign(f2,'bit.out');
reset(f1); rewrite(f2);
readln(f1,n,m);
for i:=1 to n do
begin
readln(f1,st);
for j:=1 to m do
begin
map[i,j]:=ord(st[j])-48;
a[i,j]:=max;
if map[i,j]=1 then begin a[i,j]:=0; inc(k); d[k,1]:=i; d[k,2]:=j; end;
end; end;
z[1,1]:=0;z[1,2]:=1;
z[2,1]:=1;z[2,2]:=0;
z[3,1]:=0;z[3,2]:=-1;
z[4,1]:=-1;z[4,2]:=0;
end;
procedure so(x1,x2:longint);
var
x,y,x3:longint;
begin
inc(deep); x3:=x2;
for i:=x1 to x2 do
for j:=1 to 4 do
begin
x:=d[i,1]+z[j,1]; y:=d[i,2]+z[j,2];
if (x>0)and(x<n+1)and(y>0)and(y<m+1)and(a[x,y]=max) then begin
a[x,y]:=deep; inc(x3); d[x3,1]:=x; d[x3,2]:=y; end;
end;
if x3=x2 then exit;
so(x2+1,x3);
end;
begin
init;
so(1,k);
for i:=1 to n do
begin
for j:=1 to (m-1) do
write(f2,a[i,j],' '); write(f2,a[i,m]);
writeln(f2);
end;
close(f1); close(f2);
end.