ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1008. Image Encoding

Crash? Why?
Posted by Element 3 Aug 2009 08:33
Program Ural_1008;

Const a:array[1..4,1..2] of integer=((1,0),(0,1),(-1,0),(0,-1));
      b='RTLB';

Var st:string;
    p:boolean;
    f:array[0..100,0..100] of boolean;
    x,y:array[1..10] of longint;
    minx,miny,sum,s:longint;
    sx,sy:longint;

Procedure Start;
Var k:integer;
Begin readln(st);
      k:=pos(' ',st);
      if k=0 then p:=true
      else p:=false;
End;

Procedure Init_1;
Var i,code,l:integer;
Begin val(st,l,code);
      sum:=l;
      minx:=maxlongint;
      miny:=maxlongint;
      for i:=1 to l do
          begin
           readln(x[i],y[i]);
           if x[i]<minx then minx:=x[i];
           if y[i]<miny then miny:=y[i];
          end;
      for i:=1 to l do
           f[x[i]-minx,y[i]-miny]:=true;
End;

Procedure Find;
Var i:integer;
Begin for i:=0 to miny+10 do
          if f[0,i] then break;
      sx:=0; sy:=i;
End;

Procedure Search;
Var s:array[1..1000,1..2] of integer;
    d,j,q:integer;
Begin s[1,1]:=sx; s[1,2]:=sy;
      d:=1;
      for j:=1 to sum-1 do
          Begin
           for q:=1 to 4 do
                if f[s[j,1]+a[q,1],s[j,2]+a[q,2]] then
                   begin
                    inc(d);
                    f[s[j,1]+a[q,1],s[j,2]+a[q,2]]:=false;
                    s[d,1]:=s[j,1]+a[q,1];
                    s[d,2]:=s[j,2]+a[q,2];
                    write(b[q]);
                   end;
           writeln(',');
          End;
End;

Procedure Init_2;
Var xx,yy,code,p,d,j,aa,bb,k,kk,q,ans:longint;
    s:array[1..1000,1..2] of integer;
Begin fillchar(f,sizeof(f),false);
      val(copy(st,1,pos(' ',st)-1),xx,code);
      val(copy(st,pos(' ',st)+1,length(st)-pos(' ',st)+1),yy,code);
      f[xx,yy]:=true;
      readln(st);
      p:=1; d:=1;Q:=1;
      s[1,1]:=xx; s[1,2]:=yy;
      while st<>'.' do
            begin
             xx:=s[p,1]; yy:=s[p,2];
             for j:=1 to length(st)-1 do
                 begin
                 aa:=a[pos(st[j],b),1]; bb:=a[pos(st[j],b),2];
                 f[xx+aa,yy+bb]:=true;
                 inc(q);
                 s[q,1]:=xx+aa; s[q,2]:=yy+bb;
                 end;
             inc(p);
             readln(st);
            end;
      ans:=0;
      for k:=1 to 10 do
          for kk:=1 to 10 do
              if f[k,kk] then inc(ans);
      writeln(ans);
      for k:=1 to 10 do
          for kk:=1 to 10 do
              if f[k,kk] then writeln(k,' ',kk);
End;

Procedure Main;
Begin
      Start;
      If p then
         Begin
           Init_1;
           Find;
           s:=sum;
           Writeln(sx+minx,' ',sy+miny);
           f[sx,sy]:=false;
           Search;
           Writeln('.');
         End
      Else
         Init_2;
End;
Begin Main;
End.