Cod sursa(job #749751)
Utilizator | Data | 18 mai 2012 17:08:04 | |
---|---|---|---|
Problema | Rj | Scor | 100 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 3.31 kb |
Program Romeo_dinamic;
type matrice=array[-2..101,-2..101] of integer;
var bufi,bufa : array[0..1 shl 25] of char;
i,n,j,m,max : longint;
a,b:matrice; c:char;
l01,l02,c01,c02 : integer;
Procedure undanumerica(var a:matrice; l0,c0,p,q:integer);
var u:integer;
begin
u:=1;
while a[p,q]=0 do
begin
for i:=1 to n do
for j:=1 to m do
if a[i,j]=u then begin
if a[i-1,j]=0 then a[i-1,j]:=u+1; {Nord}
if a[i-1,j-1]=0 then a[i-1,j-1]:=u+1; {Nord-Vest}
if a[i-1,j+1]=0 then a[i-1,j+1]:=u+1; {Nord-Est}
if a[i+1,j]=0 then a[i+1,j]:=u+1; {Sud}
if a[i+1,j-1]=0 then a[i+1,j-1]:=u+1; {Sud-Vest}
if a[i+1,j+1]=0 then a[i+1,j+1]:=u+1; {Sud-Est}
if a[i,j-1]=0 then a[i,j-1]:=u+1; {Vst}
if a[i,j+1]=0 then a[i,j+1]:=u+1; {Est};
end;
u:=u+1;
end;
end;
Procedure tipar;
var i0,j0,tmin:integer;
begin
tmin:=maxint;
for i:=n downto 1 do
for j:=m downto 1 do
if (a[i,j]<>-1) and
(a[i,j]=b[i,j]) then begin
if (a[i,j]<=tmin) and
(a[i,j]<>0) then begin
tmin:=a[i,j];
i0:=i;
j0:=j;
end;
end;
write(tmin,' ',i0,' ',j0);
end;
begin
assign(input,'rj.in'); reset(input);
assign(output,'rj.out'); rewrite(output);
settextbuf(input,bufi); settextbuf(output,bufa);
max:=1; readln(n,m);
for i:=1 to n do
begin
for j:=1 to m do begin
read(c);
if c='X' then begin
a[i,j]:=-1;
b[i,j]:=-1;
end
else if c='R' then begin
a[i,j]:=1;
l01:=i;
c01:=j;
end
else if c='J' then begin
b[i,j]:=1;
l02:=i;
c02:=j;
end;
end;
readln;
end;
for i:=0 to m+1 do begin
a[0,i]:=-1; b[0,i]:=-1;
a[n+1,i]:=-1; b[n+1,i]:=-1;
end;
for i:=0 to n+1 do begin
a[i,0]:=-1; b[i,0]:=-1;
a[i,m+1]:=-1; b[i,m+1]:=-1;
end;
undanumerica(a,l01,c01,l02,c02);
undanumerica(b,l02,c02,l01,c01);
tipar;
close(input); close(output);
end.