记录编号 14118 评测结果 AAAAAAAAAA
题目名称 不听话的机器人 最终得分 100
用户昵称 Gravatarmaxiem 是否通过 通过
代码语言 Pascal 运行时间 2.336 s
提交时间 2009-10-27 09:23:03 内存使用 0.28 MiB
显示代码纯文本
program nrobot;
const dir:array [0..3,1..2] of shortint=((-1,0),(0,1),(1,0),(0,-1));
var
  max,d,d0,x0,y0,i,j,n,m,x,y:integer;
  a,b:array [1..100,1..100,0..3] of integer;
  table:array [1..100,1..100] of boolean;
  command:array [1..1000] of char;
  s:string;
begin
  fillchar (table,sizeof(table),0);
  fillchar (a,sizeof(a),0);
  fillchar (b,sizeof(b),0);
  assign (input,'nrobot.in');
  reset (input);
  readln (n,m,x,y);
  for i:=1 to n do begin
    readln (s);
    for j:=1 to n do if s[j]='*' then table[i,j]:=true;
  end;
  for i:=1 to m do begin
    readln (s);
    command[i]:=s[1];
  end;
  close (input);
  assign (output,'nrobot.out');
  rewrite (output);
  a[x,y,0]:=1;max:=0;
  for i:=1 to m do begin
    for x:=1 to n do for y:=1 to n do for d:=0 to 3 do if a[x,y,d]>0 then begin
      x0:=x;y0:=y;d0:=d;
      case command[i] of
        'F':begin
          inc(x0,dir[d,1]);
          inc(y0,dir[d,2]);
        end;
        'B':begin
          dec(x0,dir[d,1]);
          dec(y0,dir[d,2]);
        end;
        'L':d0:=(d0+3) mod 4;
        'R':d0:=(d0+5) mod 4;
      end;
      if (x0>=1) and (x0<=n) and (y0>=1) and (y0<=n) and (table[x0,y0]=false) then begin
        if a[x0,y0,d0]<a[x,y,d]+1 then begin
          b[x0,y0,d0]:=a[x,y,d]+1;
          if b[x0,y0,d0]>max then max:=b[x0,y0,d0];
        end;
      end;
    end;
    for x:=1 to n do for y:=1 to n do for d:=0 to 3 do
      if a[x,y,d]<b[x,y,d] then a[x,y,d]:=b[x,y,d];
  end;
  writeln (m-max+1);
  close (output);
end.