记录编号 7145 评测结果 AAAAAAAAAA
题目名称 [USACO Dec08] 花园栅栏 最终得分 100
用户昵称 Gravatar辨机ZN 是否通过 通过
代码语言 Pascal 运行时间 0.025 s
提交时间 2008-11-06 20:39:19 内存使用 0.18 MiB
显示代码纯文本
program ex(f1,f2);
 type
  ka=record
   x,y:integer;
  end;
  zn=array [-10..105,-10..105,1..4] of boolean;
  fa=array [-10..105,-10..105] of boolean;
  da=array [0..30000] of ka;
 var
  flag:fa; ch:char; flag2:zn;
  f1,f2:text; i,j,k,m,n,p,q,l,s,ans:longint;
  head,tail,tou,wei,xx,yy,step,tot:longint;
 procedure init;
  begin
  assign(f1,'fence.in');  reset(f1);
  assign(f2,'fence.out'); rewrite(f2);
  readln(f1,xx,yy,step);
  for i:=1 to step do
   begin
    read(f1,ch); read(f1,s); readln(f1);
    case ch of
     'E':begin
          for j:=1 to s do
           begin
            flag2[xx+j,yy,2]:=true;
            flag2[xx+j,yy+1,4]:=true;
           end;
          xx:=xx+s;
         end;
     'W':begin
          for j:=1 to s do
           begin
            flag2[xx-j+1,yy,2]:=true;
            flag2[xx-j+1,yy+1,4]:=true;
           end;
          xx:=xx-s;
         end;
     'S':begin
          for j:=1 to s do
           begin
            flag2[xx,yy-j+1,1]:=true;
            flag2[xx+1,yy-j+1,3]:=true;
           end;
          yy:=yy-s;
         end;
     'N':begin
          for j:=1 to s do
           begin
            flag2[xx,yy+j,1]:=true;
            flag2[xx+1,yy+j,3]:=true;
           end;
          yy:=yy+s;
         end;
    end;
   end;
   tot:=0;
  end;
 procedure find(x,y:integer);
  var
   i,j,p,k:integer;
  begin
   if flag[x,y] then exit;
   flag[x,y]:=true;
   if (flag2[x,y,1]=false)and(x+1<=100) then find(x+1,y);
   if (flag2[x,y,3]=false)and(x-1>=1) then find(x-1,y);
   if (flag2[x,y,4]=false)and(y-1>=1) then find(x,y-1);
   if (flag2[x,y,2]=false)and(y+1<=100) then find(x,y+1);
  end;
 procedure bfs;
  begin
   for i:=1 to 100 do
    begin
     find(0,i);
     find(101,i);
     find(i,0);
     find(i,101);
    end;
  end;

 begin
  init;
  bfs;
  tot:=0;
  for i:=1 to 100 do
   for j:=1 to 100 do
    if flag[i,j] then inc(tot);
  writeln(f2,10000-tot);
  close(f1);
  close(f2);
 end.