Cod sursa(job #77663)

Utilizator ProtomanAndrei Purice Protoman Data 14 august 2007 17:15:34
Problema Rj Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.9 kb
const v1:array[1..8] of shortint=(0,0,1,1,1,-1,-1,-1);
      v2:array[1..8] of shortint=(-1,1,-1,0,1,-1,0,1);

var m:array[0..110,0..110] of integer;
    i,j,n,mi,ai,aj,h,mn:longint;
    vi,vj:array[1..11000] of longint;
    c:char;
    f1,f2:text;

procedure vecini(x,y:longint);
begin
        if m[x,y]=m[vi[i],vj[i]]+1 then
                if m[x,y]<mn then
                begin
                        mn:=m[x,y];
                        ai:=x;
                        aj:=y;
                end;
        if m[x,y]=maxint then
        begin
                m[x,y]:=m[vi[i],vj[i]]+1;
                inc(h);
                vi[h]:=x;
                vj[h]:=y;
        end;
end;

procedure lee;
begin
        while i<h do
        begin
                inc(i);
                for j:=1 to 8 do
                        vecini(vi[i]+v1[j],vj[i]+v2[j]);
        end;
end;

begin
        assign(f1,'rj.in');
        reset(f1);
        assign(f2,'rj.out');
        rewrite(f2);
        readln(f1,n,mi);
        for i:=1 to n do
        begin
                for j:=1 to mi do
                begin
                        read(f1,c);
                        m[i,j]:=maxint;
                        if c='X' then m[i,j]:=-1;
                        if c='J' then
                        begin
                                vi[1]:=i;
                                vj[1]:=j;
                                m[i,j]:=0;
                        end;
                        if c='R' then
                        begin
                                vi[2]:=i;
                                vj[2]:=j;
                                m[i,j]:=0;
                        end;
                end;
                readln(f1);
        end;
        mn:=maxint;
        i:=0;
        h:=2;
        lee;
        writeln(f2,mn+1,' ',ai,' ',aj);
        close(f1);
        close(f2);
end.