比赛 |
2008haoi模拟训练3 |
评测结果 |
AAWEAEEEEE |
题目名称 |
位图 |
最终得分 |
30 |
用户昵称 |
thegy |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-04-24 09:29:26 |
显示代码纯文本
program bit;
type
st=array[1..128]of char;
var
fin,fout:text;
n,m,i,j,head,tail,tx,ty:longint;
g:array[1..128]of st;
g0:array[1..128,1..128]of longint;
v:array[1..128,1..128]of boolean;
lx,ly,lc:array[1..20000]of longint;
function isin(x,y:longint):boolean;
begin
if (x>=1) and (x<=m) and (y>=1) and (y<=n) then isin:=true
else isin:=false;
end;
begin
assign(fin,'bit.in'); reset(fin);
assign(fout,'bit.out'); rewrite(fout);
readln(fin,n,m);
for i:=1 to n do
readln(fin,g[i]);
tail:=0;
for i:=1 to n do
for j:=1 to m do v[i,j]:=false;
for i:=1 to n do
for j:=1 to m do
begin
if g[i,j]='1' then
begin
inc(tail);
ly[tail]:=i;
lx[tail]:=j;
lc[tail]:=0;
v[i,j]:=true;
end;
end;
head:=1;
repeat
tx:=lx[head]+1;
ty:=ly[head];
if isin(tx,ty) then
begin
if not(v[ty,tx]) then
begin
v[ty,tx]:=true;
inc(tail);
lx[tail]:=tx;
ly[tail]:=ty;
lc[tail]:=lc[head]+1;
end;
end;
tx:=lx[head]-1;
ty:=ly[head];
if isin(tx,ty) then
begin
if not(v[ty,tx]) then
begin
v[ty,tx]:=true;
inc(tail);
lx[tail]:=tx;
ly[tail]:=ty;
lc[tail]:=lc[head]+1;
end;
end;
tx:=lx[head];
ty:=ly[head]+1;
if isin(tx,ty) then
begin
if not(v[ty,tx]) then
begin
v[ty,tx]:=true;
inc(tail);
lx[tail]:=tx;
ly[tail]:=ty;
lc[tail]:=lc[head]+1;
end;
end;
tx:=lx[head];
ty:=ly[head]-1;
if isin(tx,ty) then
begin
if not(v[ty,tx]) then
begin
v[ty,tx]:=true;
inc(tail);
lx[tail]:=tx;
ly[tail]:=ty;
lc[tail]:=lc[head]+1;
end;
end;
inc(head);
until head>tail;
for i:=1 to tail do
begin
g0[ly[i],lx[i]]:=lc[i];
end;
for i:=1 to n do
begin
for j:=1 to m-1 do
write(fout,g0[i,j],' ');
writeln(fout,g0[i,m]);
end;
close(fout);
end.