Cod sursa(job #749643)
Utilizator | Data | 17 mai 2012 22:09:55 | |
---|---|---|---|
Problema | Rj | Scor | 0 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 3.76 kb |
Program P1;
type matrice=array[-2..101,-2..101] of integer;
var fi,fo : text;
i,n,j,m ,max: longint;
a,b : matrice; c:char;
l01,l02,c01,c02 : integer;
Procedure tipar;
var i0,j0,tmin,min : integer;
begin
tmin:=maxint;
for i:=n downto 1 do
for j:=m downto 1 do
if a[i,j]<>-1 then
begin
if a[i,j]>b[i,j] then min:=a[i,j]
else min:=b[i,j];
if (min<>0) and (min<=tmin) then begin
tmin:=min;
i0:=i;
j0:=j;
end;
end;
write(fo,tmin,' ',i0,' ',j0);
end;
Procedure undanumerica(var a:matrice; l0,c0:integer);
var u,k:longint;
begin
if a[l0,c0+1]=0 then a[l0,c0+1]:=2;
if a[l0,c0-1]=0 then a[l0,c0-1]:=2;
if a[l0-1,c0]=0 then a[l0-1,c0]:=2;
if a[l0-1,c0-1]=0 then a[l0-1,c0-1]:=2;
if a[l0-1,c0+1]=0 then a[l0-1,c0+1]:=2;
if a[l0+1,c0]=0 then a[l0+1,c0]:=2;
if a[l0+1,c0-1]=0 then a[l0+1,c0-1]:=2;
if a[l0+1,c0+1]=0 then a[l0+1,c0+1]:=2;
u:=2;
for k:=1 to max 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;{Est}
if a[i,j+1]=0 then a[i,j+1]:=u+1;{Vest}
end;
u:=u+1;
end;
end;
begin
assign(fi,'rj.in'); reset(fi); readln(fi,n,m);
assign(fo,'rj.out'); rewrite(fo); max:=1;
for i:=1 to n do
begin
for j:=1 to n do begin
read(fi,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;
max:=max+1;
end
else
if c='J' then begin
b[i,j]:=1;
l02:=i;
c02:=j;
max:=max+1;
end
else max:=max+1;
end;
readln(fi);
end;
max:=max+1;
for i:=0 to m+1 do begin a[0,i]:=-1; a[n+1,i]:=-1; end;
for i:=0 to n+1 do begin a[i,0]:=-1; a[i,m+1]:=-1; end;
undanumerica(a,l01,c01);
undanumerica(b,l02,c02);
tipar;
close(fi); close(fo);
end.