记录编号 6876 评测结果 AAAAAAAAAA
题目名称 [USACO Dec08] 花园栅栏 最终得分 100
用户昵称 Gravatarname:弓虽 是否通过 通过
代码语言 Pascal 运行时间 0.045 s
提交时间 2008-11-05 10:57:52 内存使用 0.35 MiB
显示代码纯文本
program fence;
type
  node=record
         n,e,w,s:boolean;
       end;
var
  fin,fout:text;
  x,y,z,i,j,a,tot:longint;
  c:char;
  g:array[-120..102,-120..102]of node;
  v:array[-120..102,-120..102]of boolean;

procedure floodfill(x,y:longint);
begin
  if v[x,y] then exit;
  v[x,y]:=true;
  if not(g[x,y].n) then floodfill(x+1,y);
  if not(g[x,y].e) then floodfill(x,y+1);
  if not(g[x,y].s) then floodfill(x-1,y);
  if not(g[x,y].w) then floodfill(x,y-1);
end;
begin
  assign(fin,'fence.in'); reset(fin);
  assign(fout,'fence.out'); rewrite(fout);
  for i:=0 to 101 do
    for j:=0 to 101 do begin
      g[i,j].n:=false;
      g[i,j].w:=false;
      g[i,j].s:=false;
      g[i,j].e:=false;
    end;
  for i:=1 to 100 do begin
    g[101,i].n:=true;
    g[101,i].e:=true;
    g[101,i].w:=true;
    g[i,0].w:=true;
    g[i,0].n:=true;
    g[i,0].s:=true;
    g[0,i].s:=true;
    g[0,i].w:=true;
    g[0,i].e:=true;
    g[i,101].n:=true;
    g[i,101].e:=true;
    g[i,101].s:=true;
  end;
  readln(fin,y,x,z);
  for i:=1 to z do begin
    readln(fin,c,a);
    if c='N' then begin
      for j:=1 to a do begin
        g[x+j,y].e:=true; g[x+j,y+1].w:=true;
      end;
      x:=x+a;
    end;
    if c='E' then begin
      for j:=1 to a do begin
        g[x+1,y+j].s:=true;
        g[x,y+j].n:=true;
      end;
      y:=y+a;
    end;
    if c='S' then begin
      for j:=1 to a do begin
        g[x-j+1,y].e:=true; g[x-j+1,y+1].w:=true;
      end;
      x:=x-a;
    end;
    if c='W' then begin
      for j:=1 to a do begin
        g[x+1,y-j+1].s:=true;
        g[x,y-j+1].n:=true;
      end;
      y:=y-a;
    end;
  end;
  for i:=0 to 101 do
    for j:=0 to 101 do begin
      v[i,j]:=false;
    end;
  for i:=1 to 100 do begin
    if not(v[101,i]) then floodfill(101,i);
    if not(v[i,101]) then floodfill(i,101);
    if not(v[0,i]) then floodfill(0,i);
    if not(v[i,0]) then floodfill(i,0);
  end;
  tot:=0;
  for i:=1 to 100 do
    for j:=1 to 100 do begin
      if v[i,j] then inc(tot);
    end;
  writeln(fout,10000-tot);
  close(fin);
  close(fout);
end.