比赛 20091023练习题 评测结果 WWWWWWWWWT
题目名称 不听话的机器人 最终得分 0
用户昵称 Achilles 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-10-26 09:04:05
显示代码纯文本
program nrobot;
var
  n,m,x,y,i,j,k,l,now,max:integer;
  s:string;
  move:array[0..3,1..2]of integer;
  sz:array[0..1,0..11,0..11,0..3]of integer;
  tab:array[0..101,0..101]of char;
begin
  move[0,1]:=-1;
  move[0,2]:=0;
  move[1,1]:=0;
  move[1,2]:=1;
  move[2,1]:=1;
  move[2,2]:=0;
  move[3,1]:=0;
  move[3,2]:=-1;
  assign(input,'nrobot.in');
  assign(output,'nrobot.out');
  reset(input);
  rewrite(output);
  readln(n,m,x,y);
  for i:=0 to n+1 do
    for j:=0 to n+1 do
      tab[i,j]:='*';
  fillchar(sz,sizeof(sz),0);
  for i:=1 to n do
  begin
    for j:=1 to n do
      read(tab[i,j]);
    readln;
  end;
  now:=0;
  max:=0;
  for i:=1 to m do
  begin
    readln(s);
    sz[now]:=sz[(now+1)mod 2];
    if s='LEFT' then begin
      for j:=1 to n do
      begin
        for k:=1 to n do
        begin
          if tab[j,k]='.' then
            for l:=0 to 3 do
            begin
              if sz[(now+1)mod 2,j,k,(l+1)mod 4]+1>sz[now,j,k,l] then sz[now,j,k,l]:=sz[(now+1)mod 2,j,k,(l+1)mod 4]+1;
            end;
        end;
      end;
    end;
    if s='RIGHT' then begin
      for j:=1 to n do
      begin
        for k:=1 to n do
        begin
          if tab[j,k]='.' then
            for l:=0 to 3 do
            begin
              if sz[(now+1)mod 2,j,k,(l+3)mod 4]+1>sz[now,j,k,l] then sz[now,j,k,l]:=sz[(now+1)mod 2,j,k,(l+3)mod 4]+1;
            end;
        end;
      end;
    end;
    if s='FORWARD' then begin
      for j:=1 to n do
      begin
        for k:=1 to n do
        begin
          if tab[j,k]='.' then
            for l:=0 to 3 do
            begin
              if tab[j+move[l,1],k+move[l,2]]='.' then
                if sz[(now+1)mod 2,j,k,l]+1>sz[now,j+move[l,1],k+move[l,2],l] then
                  sz[now,j+move[l,1],k+move[l,2],l]:=sz[(now+1)mod 2,j,k,l]+1;
            end;
        end;
      end;
    end;
    if s='BACK' then begin
      for j:=1 to n do
      begin
        for k:=1 to n do
        begin
          if tab[j,k]='.' then
            for l:=0 to 3 do
            begin
              if tab[j-move[l,1],k-move[l,2]]='.' then
                if sz[(now+1)mod 2,j,k,l]+1>sz[now,j-move[l,1],k-move[l,2],l] then
                  sz[now,j-move[l,1],k-move[l,2],l]:=sz[(now+1)mod 2,j,k,l]+1;
            end;
        end;
      end;
    end;
    now:=(now+1)mod 2;
    for j:=1 to n do
      for k:=1 to n do
        for l:=0 to 3 do
          if sz[(now+1)mod 2,j,k,l]>max then max:=sz[(now+1)mod 2,j,k,l];
    for j:=1 to n do
      for k:=1 to n do
        for l:=0 to 3 do
          sz[now,j,k,l]:=0;
  end;
  writeln(m-max);
  close(input);
  close(output);
end.