比赛 |
20091023练习题 |
评测结果 |
AATTTTTTTT |
题目名称 |
不听话的机器人 |
最终得分 |
20 |
用户昵称 |
maxiem |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2009-10-26 10:57:07 |
显示代码纯文本
program nrobot;
const dir:array [1..4,1..2] of shortint=((-1,0),(0,1),(1,0),(0,-1));
var
i,j,n,m,x,y:integer;
dp:array [1..100,1..100,1..4] of integer;
table:array [1..100,1..100] of boolean;
command:array [1..1000] of char;
s:string;
procedure get(x,y,i,d,pas:integer);
var min,x0,y0,d0:integer;
begin
min:=maxint;
if i<=m 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':begin
dec(d0);
if d0=0 then d0:=4;
end;
'R':begin
inc(d0);
if d0=5 then d0:=1;
end;
end;
if (x0<=n) and (x0>=1) and (y0<=n) and (y0>=1) and (table[x0,y0]=false) then begin
get(x0,y0,i+1,d0,pas);
min:=dp[x0,y0,d0];
end;
get(x,y,i+1,d,pas+1);
if min>dp[x,y,d] then min:=dp[x,y,d];
end;
if min=maxint then dp[x,y,d]:=pas else dp[x,y,d]:=min;
end;
begin
fillchar (table,sizeof(table),0);
fillchar (dp,sizeof(dp),$FF);
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);
get(x,y,1,1,0);
writeln (dp[x,y,1]);
close (output);
end.