Page 147 - C:\Users\Admin\Desktop\Sach mem upweb\
P. 147
100 Problems & Solutions Trang 147
procedure loang(k:integer);
var x,y,s,u,v :integer;
begin
fillchar(q,sizeof(q),0);
dau:=1;cuoi:=1;
q[1,1]:=robot[k,1];
q[1,2]:=robot[k,2];
l[robot[k,1],robot[k,2],k]:=1;
while dau<=cuoi do
begin
x:=q[dau,1];y:=q[dau,2];
for s:=1 to 4 do
begin
u:=x+tx[s];
v:=y+ty[s];
if (u>0)and(v>0)and(u<=m)and(v<=n)and(a[u,v]=0)and(l[u,v,k]=0) then
begin
inc(cuoi);q[cuoi,1]:=u;q[cuoi,2]:=v;
l[u,v,k]:=l[x,y,k]+1;
end;
end;
inc(dau);
end;
end;
procedure lam;
var k,i,j :integer;
meet :boolean;
begin
fillchar(l,sizeof(l),0);
ok:=true;
for k:=2 to r do
if (robot[1,1]+robot[1,2]+robot[k,1]+robot[k,2]) mod 2=1 then ok:=false;
if ok then
begin
best:=maxint;
for k:=1 to r do loang(k);
for i:=1 to m do
for j:=1 to n do
begin
meet:=true;
for k:=1 to r do meet:=meet and (l[i,j,k]>0) and (l[i,j,k]<best);
if meet then
begin
best:=0;
for k:=1 to r do
if l[i,j,k]>best then
begin
Tin học & Nhà trường 100 Đề Toán - Tin học