比赛 |
2008haoi模拟训练3 |
评测结果 |
AAATWTTTTT |
题目名称 |
位图 |
最终得分 |
30 |
用户昵称 |
NickName |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-04-24 10:44:40 |
显示代码纯文本
program bitt;
var bi,bo:text;
n,m:integer;
i,j:integer;
x1,x2:integer;
now:string;
zd:integer;
bit:array[1..182,1..182] of boolean;
procedure go(a,b:integer);
var xx,yy:integer;
begin
for xx:=a downto 1 do
begin
for yy:=b downto 1 do
if ((bit[xx,yy]=true) and (abs(yy-b)+abs(xx-a)<zd)) then zd:=abs(yy-b)+abs(xx-a);
if ((yy-b>zd) or (xx-a>zd)) then exit;
end;
for xx:=a to n do
begin
for yy:=b downto 1 do
if ((bit[xx,yy]=true) and (abs(yy-b)+abs(xx-a)<zd)) then zd:=abs(yy-b)+abs(xx-a);
if ((yy-b>zd) or (xx-a>zd)) then exit;
end;
for xx:=a downto 1 do
begin
for yy:=b to m do
if ((bit[xx,yy]=true) and (abs(yy-b)+abs(xx-a)<zd)) then zd:=abs(yy-b)+abs(xx-a);
if ((yy-b>zd) or (xx-a>zd)) then exit;
end;
for xx:=a to n do
begin
for yy:=b to m do
if ((bit[xx,yy]=true) and (abs(yy-b)+abs(xx-a)<zd)) then zd:=abs(yy-b)+abs(xx-a);
if ((yy-b>zd) or (xx-a>zd)) then exit;
end;
end;
begin
assign(bi,'bit.in');
assign(bo,'bit.out');
reset(bi);
rewrite(bo);
readln(bi,n,m);
for x1:=1 to n do
begin
readln(bi,now);
for x2:=1 to m do
begin
if now[x2]='1' then bit[x1,x2]:=true
else bit[x1,x2]:=false;
end;
end;
for x1:=1 to n do
begin
for x2:=1 to m do
begin
if bit[x1,x2]=false then
begin
zd:=365;
go(x1,x2);
write(bo,zd);
end
else write(bo,'0');
if x2<m then write(bo,' ');
end;
writeln(bo);
end;
close(bi);
close(bo);
end.