记录编号 26834 评测结果 AAATT
题目名称 管道系统 最终得分 60
用户昵称 Gravatarlizhe 是否通过 未通过
代码语言 Pascal 运行时间 2.001 s
提交时间 2011-07-27 19:47:22 内存使用 0.12 MiB
显示代码纯文本
program paipe;
const
  fangxiang:array['A'..'Z']of longint=(0,0,0,2,0,0,0,0,0,0,0,3,0,0,0,0,0,4,0,0,1,0,0,0,0,0);
  kind:array[0..14,1..4,1..4]of longint=(((0,0,0,0),(0,0,0,0),(0,0,0,0),(0,0,0,0)),
                                         ((0,1,0,0),(1,0,0,0),(0,0,0,0),(0,0,0,0)),
                                         ((0,0,0,0),(0,0,0,0),(0,0,0,1),(0,0,1,0)),
                                         ((0,0,1,0),(0,0,0,0),(1,0,0,0),(0,0,0,0)),
                                         ((0,0,0,0),(0,0,1,0),(0,1,0,0),(0,0,0,0)),
                                         ((0,0,0,0),(0,0,0,1),(0,0,0,0),(0,1,0,0)),
                                         ((0,0,0,1),(0,0,0,0),(0,0,0,0),(1,0,0,0)),
                                         ((0,1,1,0),(1,0,1,0),(1,1,0,0),(0,0,0,0)),
                                         ((0,0,0,0),(0,0,1,1),(0,1,0,1),(0,1,1,0)),
                                         ((0,1,0,1),(1,0,0,1),(0,0,0,0),(1,1,0,0)),
                                         ((0,0,1,1),(0,0,0,0),(1,0,0,1),(1,0,1,0)),
                                         ((0,1,1,1),(1,0,1,1),(1,1,0,1),(1,1,1,0)),
                                         ((0,1,0,0),(1,0,0,0),(0,0,0,1),(0,0,1,0)),
                                         ((0,0,1,0),(0,0,0,1),(1,0,0,0),(0,1,0,0)),
                                         ((0,0,0,1),(0,0,1,0),(0,1,0,0),(1,0,0,0)));
var
  i,j,n,m,sx,sy,sf,ex,ey,ef,t:longint;
  map:array[1..6,1..6]of longint;
  bool:array[1..6,1..6,1..5]of boolean;
  ch:char;
procedure adj(var x1,y1,z1:longint);
begin
  if z1=1 then begin x1:=x1-1; y1:=y1; z1:=2; exit end;
  if z1=2 then begin x1:=x1+1; y1:=y1; z1:=1; exit end;
  if z1=3 then begin x1:=x1; y1:=y1-1; z1:=4; exit end;
  if z1=4 then begin x1:=x1; y1:=y1+1; z1:=3; exit end
end;

procedure dfs(x,y,z,step:longint);
var
  l,xx,yy,zz:longint;
begin
  if (x=ex) and (y=ey) and (z=ef) then
    inc(t)
  else
  begin
    xx:=x; yy:=y; zz:=z;
    if step<>1 then
      adj(xx,yy,zz);
    if (xx>=1) and (xx<=m) and
       (yy>=1) and (yy<=n) then
    for l:=1 to 4 do
      if (kind[map[xx,yy],zz,l]=1) and bool[xx,yy,l] and bool[xx,yy,5] then
      begin
        if (map[xx,yy]>=7) and (map[xx,yy]<=11) then
          bool[xx,yy,5]:=false;
        bool[xx,yy,l]:=false;
        dfs(xx,yy,l,step+1);
        bool[xx,yy,l]:=true;
        if (map[xx,yy]>=7) and (map[xx,yy]<=11) then
          bool[xx,yy,5]:=true;
      end
  end
end;

procedure init;
begin
  read(m,n);
  for i:=1 to m do
    for j:=1 to n do
      read(map[i,j]);
  readln;
  read(sx,sy); repeat read(ch) until (ch>'A') and (ch<'Z'); sf:=fangxiang[ch];
  read(ex,ey); repeat read(ch) until (ch>'A') and (ch<'Z'); ef:=fangxiang[ch];
  fillchar(bool,sizeof(bool),true);
  t:=0;
end;

procedure main;
begin
  assign(input,'paipe.in');
  reset(input);
  assign(output,'paipe.out');
  rewrite(output);
  repeat
    init;
    dfs(sx,sy,sf,1);
    writeln(t);
    readln
  until eof;
  close(input);
  close(output)
end;

begin
  main
end.