记录编号 6959 评测结果 AAAAAAAAAA
题目名称 [USACO Dec08] 花园栅栏 最终得分 100
用户昵称 Gravatarlc 是否通过 通过
代码语言 Pascal 运行时间 0.021 s
提交时间 2008-11-05 19:27:51 内存使用 0.16 MiB
显示代码纯文本
program ex196;
 const
   maxd=100;
 var
     C:array[1..100,1..100] of boolean;
     Pa:array[0..100,0..100] of record
         up,down,left,right:boolean;
         end;
     n,ans:integer;

procedure init;
 var
    dir:char;
    x,y,z,i,j,len:integer;

 begin
  readln(x,y,z);
  fillchar(pa,sizeof(pa),1);
  for i:=1 to z do
    begin
    readln(dir,len);
    case dir of
    'N':  begin
            inc(y);
                    for j:=1 to len do
                      begin
                        Pa[x,y].right:=false;  Pa[x+1,y].left:=false;
                        inc(y);
                      end;
             dec(y);
           end;

     'S':  begin
                     for j:=1 to len do
                       begin
                         Pa[x,y].right:=false; Pa[x+1,y].left:=false;
                         dec(y);
                       end;
            end;

      'W':  begin
                     for j:=1 to len do
                       begin
                         Pa[x,y].up:=false; Pa[x,y+1].down:=false;
                         dec(x);
                       end;
            end;

       'E':  begin
                 inc(x);
                    for j:=1 to len do
                      begin
                        Pa[x,y].up:=false; Pa[x,y+1].down:=false;
                        inc(x);
                      end;
                 dec(x);
              end;
        end; //case
     end;

end;

procedure fill(x,y:integer);
 begin
  if C[x,y] then exit;
  C[x,y]:=true;
  if Pa[x,y].up and (y+1<=maxd) then fill(x,y+1);
  if Pa[x,y].down and (y-1>=1)  then fill(x,y-1);
  if Pa[x,y].left and (x-1>=1)  then fill(x-1,y);
  if Pa[x,y].right and (x+1<=maxd) then fill(x+1,y);
 end;

procedure main;
 var
     i,j:integer;

 begin
   for i:=1 to maxd do
   if Pa[i,1].down then begin fill(i,1);  end;
   for i:=1 to maxd do
   if Pa[i,maxd].up then begin fill(i,maxd);  end;
   for j:=1 to maxd do
   if Pa[1,j].left then begin fill(1,j);  end;
   for j:=1 to maxd do
   if Pa[maxd,j].right then begin fill(maxd,j);  end;

 end;

procedure print;
 var
    i,j:integer;
 begin
  ANS:=0;
  for i:=1 to maxd do
   for j:=1 to maxd do
   if C[i,j] then inc(ans);
  ans:=maxd*maxd-ans;
  writeln(ans);
 end;


begin
 assign(input,'fence.in'); reset(input);
 assign(output,'fence.out'); rewrite(output);
 init;
 main;
 print;
 close(input); close(output);
end.