ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1101. Робот в поле

Can onyone give me a test. I get Output Limit (+)
Послано Andrey Popyk (popyk@ief.tup.km.ua) 15 мар 2002 19:00
Can onyone tell me, where my programm fails.
My programm gets Output Limit, and I don't know where it wrong.
I convert Boolean expression into a postfix form and simply simulate
a robot movement.

CONST Dim = 10007;
      Dim2 = 101;

TYPE TBuf = Array[0..Dim] of char;
VAR Buf,Stack:TBuf;
    BST:Array[0..3007] of boolean;
    BP,SP:integer;
    CurrCh:char;
    F:Array[-Dim2..Dim2,-Dim2..Dim2] of char;
    Reg:Array['A'..'\'] of boolean;
    N:integer;

FUNCTION GetLexem:char;
var S:string;
begin
  S:='';
  while not (CurrCh in ['A'..'Z','(',')',#13]) do read(CurrCh);
  if CurrCh=#13 then begin GetLexem:=#13; Exit end;
  if (CurrCh='(') or (CurrCh=')') then begin GetLexem:=CurrCh; read
(CurrCh); Exit end;
  while CurrCh in ['A'..'Z'] do
    begin S:=S+CurrCh; read(CurrCh) end;
  if S='NOT' then S:='!';
  if S='AND' then S:='&';
  if S='OR' then S:='|';
  if S='TRUE' then S:='[';
  if S='FALSE' then S:='\';
  GetLexem:=S[1];
  if length(S)>1 then begin writeln('Error!'); Halt(0) end;
end;

PROCEDURE AddBuf(C:char);
begin
  inc(BP); Buf[BP]:=C;
end;

FUNCTION Prior(C:char):integer;
begin
  case C of
    '(':Prior:=0;
    '|':Prior:=1;
    '&':Prior:=2;
    '!':Prior:=3;
  end;
end;

PROCEDURE AddStack(C:char);
var P:integer;
begin
  if C='(' then begin inc(SP); Stack[SP]:='('; Exit end;
  if C=')' then begin
                  while Stack[SP]<>'(' do begin AddBuf(Stack[SP]); dec
(SP) end;
                  dec(SP);
                  Exit;
                end;
  P:=Prior(C);
  while (SP>0) and (P<=Prior(Stack[SP])) do
  begin
    AddBuf(Stack[SP]);
    dec(SP);
  end;
  inc(SP); Stack[SP]:=C;
end;

PROCEDURE ConvertProgram;
var C:char;
begin
  BP:=0; SP:=0;
  CurrCh:=#0;
  repeat
    C:=GetLexem;
    if C=#13 then break;
    if (C>='A') and (C<='\') then AddBuf(C) else AddStack(C);
  until C=#13;
  read(CurrCh);
  while SP>0 do begin AddBuf(Stack[SP]); dec(SP) end;
end;

PROCEDURE ReadPoints;
var M,K,R,C,i:integer;
    ch1,ch2:char;
begin
  readln(N,M,K);
  for i:=1 to M do
  begin
    readln(R,C);
    F[R,C]:='#';
  end;
  for i:=1 to K do
  begin
    readln(R,C,ch1,ch2);
    F[R,C]:=ch2;
  end;
end;

PROCEDURE TurnRight(var DR,DC:integer);
begin
  if Abs(DR)=1 then begin DC:=-DR; DR:=0 end
               else begin DR:=DC; DC:=0 end;
end;

PROCEDURE TurnLeft(var DR,DC:integer);
begin
  if Abs(DR)=1 then begin DC:=DR; DR:=0 end
               else begin DR:=-DC; DC:=0 end;
end;

FUNCTION Count:boolean;
var BSP,i:integer;
begin
  BSP:=0;
  for i:=1 to BP do
  begin
    if Buf[i] in ['A'..'\']
      then begin inc(BSP); BST[BSP]:=Reg[Buf[i]] end
      else begin
             if Buf[i]='!' then BST[BSP]:=not BST[BSP];
             if Buf[i]='&' then begin BST[BSP]:=BST[BSP-1] and BST
[BSP]; dec(BSP) end;
             if Buf[i]='|' then begin BST[BSP]:=BST[BSP-1] or BST
[BSP]; dec(BSP) end;
           end;
  end;
  Count:=BST[BSP];
  if BSP<>1 then begin writeln('Error!'); Halt(0) end;
end;

PROCEDURE Simulate;
var ch:char;
    R,C,DR,DC:integer;
begin
  for ch:='A' to '\' do Reg[ch]:=false;
  Reg['[']:=true;
  R:=0; C:=0; DR:=1; DC:=0;
  if F[0,0]<>#0 then Reg[F[0,0]]:=not Reg[F[0,0]];
  repeat
    writeln(R,' ',C);
    R:=R+DR; C:=C+DC;
    if (Abs(R)>N) or (Abs(C)>N) then break;
    if F[R,C]='#' then begin
                         if Count then TurnRight(DR,DC)
                                  else TurnLeft(DR,DC);
                       end
                  else if F[R,C]<>#0 then Reg[F[R,C]]:=not Reg[F
[R,C]];
  until false;
end;

BEGIN
{ assign(INPUT,'robot.dat'); reset(INPUT);}

  ConvertProgram;
  ReadPoints;
  Simulate;
END.
Ok, just COUNT wrong.
Послано Andrey Popyk (popyk@ief.tup.km.ua) 20 мар 2002 11:56
> Can onyone tell me, where my programm fails.
> My programm gets Output Limit, and I don't know where it wrong.
> I convert Boolean expression into a postfix form and simply
simulate
> a robot movement.
>
> CONST Dim = 10007;
>       Dim2 = 101;
>
> TYPE TBuf = Array[0..Dim] of char;
> VAR Buf,Stack:TBuf;
>     BST:Array[0..3007] of boolean;
>     BP,SP:integer;
>     CurrCh:char;
>     F:Array[-Dim2..Dim2,-Dim2..Dim2] of char;
>     Reg:Array['A'..'\'] of boolean;
>     N:integer;
>
> FUNCTION GetLexem:char;
> var S:string;
> begin
>   S:='';
>   while not (CurrCh in ['A'..'Z','(',')',#13]) do read(CurrCh);
>   if CurrCh=#13 then begin GetLexem:=#13; Exit end;
>   if (CurrCh='(') or (CurrCh=')') then begin GetLexem:=CurrCh; read
> (CurrCh); Exit end;
>   while CurrCh in ['A'..'Z'] do
>     begin S:=S+CurrCh; read(CurrCh) end;
>   if S='NOT' then S:='!';
>   if S='AND' then S:='&';
>   if S='OR' then S:='|';
>   if S='TRUE' then S:='[';
>   if S='FALSE' then S:='\';
>   GetLexem:=S[1];
>   if length(S)>1 then begin writeln('Error!'); Halt(0) end;
> end;
>
> PROCEDURE AddBuf(C:char);
> begin
>   inc(BP); Buf[BP]:=C;
> end;
>
> FUNCTION Prior(C:char):integer;
> begin
>   case C of
>     '(':Prior:=0;
>     '|':Prior:=1;
>     '&':Prior:=2;
>     '!':Prior:=3;
>   end;
> end;
>
> PROCEDURE AddStack(C:char);
> var P:integer;
> begin
>   if C='(' then begin inc(SP); Stack[SP]:='('; Exit end;
>   if C=')' then begin
>                   while Stack[SP]<>'(' do begin AddBuf(Stack[SP]);
dec
> (SP) end;
>                   dec(SP);
>                   Exit;
>                 end;
>   P:=Prior(C);
>   while (SP>0) and (P<=Prior(Stack[SP])) do
>   begin
>     AddBuf(Stack[SP]);
>     dec(SP);
>   end;
>   inc(SP); Stack[SP]:=C;
> end;
>
> PROCEDURE ConvertProgram;
> var C:char;
> begin
>   BP:=0; SP:=0;
>   CurrCh:=#0;
>   repeat
>     C:=GetLexem;
>     if C=#13 then break;
>     if (C>='A') and (C<='\') then AddBuf(C) else AddStack(C);
>   until C=#13;
>   read(CurrCh);
>   while SP>0 do begin AddBuf(Stack[SP]); dec(SP) end;
> end;
>
> PROCEDURE ReadPoints;
> var M,K,R,C,i:integer;
>     ch1,ch2:char;
> begin
>   readln(N,M,K);
>   for i:=1 to M do
>   begin
>     readln(R,C);
>     F[R,C]:='#';
>   end;
>   for i:=1 to K do
>   begin
>     readln(R,C,ch1,ch2);
>     F[R,C]:=ch2;
>   end;
> end;
>
> PROCEDURE TurnRight(var DR,DC:integer);
> begin
>   if Abs(DR)=1 then begin DC:=-DR; DR:=0 end
>                else begin DR:=DC; DC:=0 end;
> end;
>
> PROCEDURE TurnLeft(var DR,DC:integer);
> begin
>   if Abs(DR)=1 then begin DC:=DR; DR:=0 end
>                else begin DR:=-DC; DC:=0 end;
> end;
>
> FUNCTION Count:boolean;
> var BSP,i:integer;
> begin
>   BSP:=0;
>   for i:=1 to BP do
>   begin
>     if Buf[i] in ['A'..'\']
>       then begin inc(BSP); BST[BSP]:=Reg[Buf[i]] end
>       else begin
>              if Buf[i]='!' then BST[BSP]:=not BST[BSP];
>              if Buf[i]=