比赛 noip20081103 评测结果 AAAEAAAAAA
题目名称 花园栅栏 最终得分 90
用户昵称 cuixiaofei 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-03 21:54:51
显示代码纯文本
//na                            :cuixiaofei;
//da                            :08_11_03;
program fence;
  const
    max                         =150;
    fx                          :array[1..4,1..2] of longint=((1,0),(0,-1),(-1,0),(0,1));
  type
    sss                         =record
                                fx:char;
                                bs:longint;
                                end;
    miaoshu                     =record
                   shu,d,x,n,b :longint;
                                end;
  var
    x,y,n                       :longint;
    zhiling                     :array[1..50000] of sss;
    a                           :array[-max..max,-max..max] of miaoshu;
    f1,f2                       :text;
  procedure init;
    var
      i                         :longint;
  begin
    assign(f1,'fence.in');
    reset(f1);
    assign(f2,'fence.out');
    rewrite(f2);
    readln(f1,x,y,n);
    for i:=1 to n do
      readln(f1,zhiling[i].fx,zhiling[i].bs);
  end;
  procedure chaozuo(fx:char;bs:longint);
    var
      i                         :longint;
  begin
    case fx of
        'N' : begin
                for i:=x+1 to x+bs do
                  begin
                    a[i,y].x:=1;
                    a[i,y+1].d:=1;
                  end;
                x:=x+bs;
              end;
        'S' : begin
                for i:=x downto x-bs+1 do
                  begin
                    a[i,y].x:=1;
                    a[i,y+1].d:=1;
                  end;
                x:=x-bs;
              end;
        'E' : begin
                for i:=y+1 to y+bs do
                  begin
                    a[x,i].b:=1;
                    a[x+1,i].n:=1;
                  end;
                y:=y+bs;
              end;
        'W' : begin
                for i:=y downto y-bs+1 do
                  begin
                    a[x,i].b:=1;
                    a[x+1,i].n:=1;
                  end;
                y:=y-bs;
              end;
      end;
  end;
  procedure ditu;
    var
      i,j                       :longint;
  begin
    for i:=-max to max do
      begin
        a[i,-max].shu:=-1;
        a[i,max].shu:=-1;
        a[-max,i].shu:=-1;
        a[max,i].shu:=-1;
      end;
    for i:=1 to n do
      begin
        chaozuo(zhiling[i].fx,zhiling[i].bs);
      end;
  end;
  procedure sousuo(x,y:longint);
    var
      i                         :longint;
  begin
    if (x>-max) and (x<max) and (y>-max) and (y<max) then
      begin
        a[x,y].shu:=1;
        for i:=1 to 4 do
          if a[x+fx[i,1],y+fx[i,2]].shu=0 then
            begin
              case i of
                1 : if a[x,y].b=0 then
                    sousuo(x+1,y);
                2 : if a[x,y].d=0 then
                    sousuo(x,y-1);
                3 : if a[x,y].n=0 then
                    sousuo(x-1,y);
                4 : if a[x,y].x=0 then
                    sousuo(x,y+1);
                end;
            end;
    end;
  end;
  procedure guangsou;
  begin
    sousuo(-max+2,-max+2);
  end;
  procedure print;
    var
      i,j,ge                    :longint;
  begin
    ge:=0;
    for i:=-max to max do
      for j:=-max to max do
        if a[i,j].shu=0 then
          inc(ge);
    writeln(f2,ge);
    close(f1);
    close(f2);
  end;
  begin
    init;
    ditu;
    guangsou;
    print;
  end.