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

Why I always get 'WRONG ANSWER'? Who can tell me how to do it right?
Posted by qwt 16 Oct 2001 19:06
program ural1008;
const
  walk:array[1..4] of integer=(10,1,-10,-1);
  ss:array[1..4] of char=('R','T','L','B');
var
  a:array[0..100] of integer;
  map:array[0..100] of boolean;
  n,x,y,i,j,k:integer;
  s:string;
  w:integer;
function strtoint(s:string):integer;
var
  i,j:integer;
begin
  val(s,i,j);
  strtoint:=i;
end;

procedure work1(n:integer);
var
  i,x,y,st,la,j,k:integer;
begin
  for i:=1 to n do begin
    readln(x,y);
    map[x*10-10+y-1]:=true;
  end;
    fillchar(a,sizeof(a),0);
    for i:=0 to 100 do
      if map[i]=true then break;
    if map[i]=false then begin writeln('.');exit;end;
    map[i]:=false;
    writeln(i div 10+1,' ',i mod 10+1);
    a[1]:=i;
    st:=0;
    la:=1;
    repeat
      st:=st+1;
      for i:=1 to 4 do
        if (map[a[st]+walk[i]])and(a[st]+walk[i] in
[0..99]) then begin
          map[a[st]+walk[i]]:=false;
          la:=la+1;
          a[la]:=a[st]+walk[i];
          write(ss[i]);
        end;
      if st<la then writeln(',') else writeln('.');
    until st=la;
end;

procedure work2(xx,yy:integer);
var
  i,t,st,la,j,k:integer;

begin
  t:=0;
{  repeat }
    fillchar(a,sizeof(a),0);
    map[xx*10-10+yy-1]:=true;
    a[1]:=xx*10-10+yy-1;
    st:=0;
    la:=1;
    t:=t+1;
    repeat
      st:=st+1;
      readln(s);
      if s='.' then break;
      t:=t+length(s)-1;
      for j:=1 to length(s)-1 do
        for i:=1 to 4 do
        if ss[i]=s[j] then begin
          map[a[st]+walk[i]]:=true;
          la:=la+1;
          a[la]:=a[st]+walk[i];
        end;
    until st=la;
{    readln(S);
    if s='.' then break else begin
      xx:=strtoint(copy(s,1,pos(' ',s)-1));
      delete(s,1,pos(' ',s));
      yy:=strtoint(s);
    end;}
{  until true=false;}
  writeln(t);
  for i:=1 to 10 do
    for j:=1 to 10 do
      if map[i*10-10+j-1] then writeln(i,' ',j);
end;

begin
  readln(s);
  k:=0;
  for i:=1 to length(s) do
    if s[i]=' ' then break;
  if i=length(s) then begin
    n:=strtoint(s);
    work1(n);
  end else
  begin
    if s='.' then begin writeln(0);exit;end else begin
      x:=strtoint(copy(s,1,pos(' ',s)-1));
      delete(s,1,pos(' ',s));
      y:=strtoint(s);
      work2(x,y);
    end;
  end;
end.