Cod sursa(job #141797)

Utilizator 05_YohnE1 La5c01 05_Yohn Data 23 februarie 2008 18:41:43
Problema Rj Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.06 kb
program gaju;
const oriz:array[1..8]of shortint=(-1,-1,-1,0,0,1,1,1);
      vert:array[1..8]of shortint=(-1,0,1,1,-1,-1,0,1);
var f,g:text;
    n,m,i,j,a,xnou,ynou,pas:integer;
    modif,motiv:boolean;
    s:string[100];
    tata:array[1..100,1..100]of boolean;
    v:array[1..100,1..100]of integer;
begin
assign(f,'rj.in');
assign(g,'rj.out');
reset(f);
rewrite(g);
readln(f,n,m);
for i:=1 to n do begin
    readln(f,s);
    for j:=1 to m do
        if (s[j]=' ')or(s='')or(s[j]=#0) then v[i,j]:=n*m+1
        else
        if s[j]='X' then v[i,j]:=0
        else
        if s[j]='R' then begin
                         v[i,j]:=1;
                         tata[i,j]:=false;
        end else
        if s[j]='J' then begin
                         v[i,j]:=1;
                         tata[i,j]:=true;
                         end;
s:='';
end;
pas:=1;
modif:=true;    motiv:=false;
while modif do begin
      modif:=false;
      for i:=1 to n do begin
          for j:=1 to m do begin
              if v[i,j]=pas then
                 for a:=1 to 8 do begin
                     xnou:=i+oriz[a];
                     ynou:=j+vert[a];
                     if( xnou in [1..n])and(ynou in [1..m]) then
                         if ((v[xnou,ynou]>pas+1)and(v[xnou,ynou]<>0))
                         then begin
                         v[xnou,ynou]:=pas+1;
                         tata[xnou,ynou]:=tata[i,j];
                         modif:=true;
                         end
                         else
                         if (v[xnou,ynou]=pas+1)and
                              (tata[i,j]<>tata[xnou,ynou]) then begin
                              motiv:=true;
                              modif:=false;
                              break;
                              end;
                 end;
                 if (motiv)and(not modif)then break;
                 end;
                 if (motiv)and(not modif)then break;
                 end;
          pas:=pas+1;
end;
writeln(g,pas,' ',xnou,' ',ynou);
close(g);close(f);
end.