比赛 noip20081103 评测结果 AWAAAWWWWA
题目名称 花园栅栏 最终得分 50
用户昵称 francis 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-03 21:04:00
显示代码纯文本
program fence;
const
fin='fence.in';
fou='fence.out';
g:array[1..4,1..2]of longint=((1,0),(0,1),(-1,0),(0,-1));
var
a,b:array[0..110,0..110]of longint;
d:array[1..15000,1..2]of longint;
all,total,x1,y1,x2,y2,p,k,l,x,y,z,i,j:longint;
ch:char;
f1,f2:text;

procedure init;
begin
assign(f1,fin);
assign(f2,fou);
reset(f1); rewrite(f2);
readln(f1,y,x,z);
a[x,y]:=1;
for i:=1 to z do
begin
 readln(f1,ch,l);
 case ch of
  'N':k:=1; 'E':k:=2; 'S':k:=3; 'W':k:=4;
  end;
 for j:=1 to l do
  begin
   x:=x+g[k,1]; y:=y+g[k,2];
   a[x,y]:=1;
  end;
end;
end;

procedure find(x,y,k:longint);
begin
 if k=1 then begin x1:=x; x2:=x; y1:=y-1; y2:=y; end;
 if k=2 then begin x1:=x; x2:=x-1; y1:=y; y2:=y; end;
 if k=3 then begin x1:=x-1; x2:=x-1; y1:=y-1; y2:=y; end;
 if k=4 then begin x1:=x;  x2:=x-1; y1:=y-1; y2:=y-1; end;
end;

procedure bfs(x,y:longint);
var
xx,yy,i,j:longint;
begin
for i:=x to y do
for j:=1 to 4 do
  begin
   xx:=d[i,1]+g[j,1]; yy:=d[i,2]+g[j,2];
   if (xx>0)and(yy>0)and(xx<=100)and(yy<=100)and(b[xx,yy]=0)then
      begin
        find(d[i,1],d[i,2],j);
        if (a[x1,y1]=0)or(a[x2,y2]=0) then begin
          b[xx,yy]:=1;  inc(all);
          inc(p); d[p,1]:=xx; d[p,2]:=yy;
        end;
      end
  end;
if p>=y+1 then bfs(y+1,p);
end;

procedure main(x,y:longint);
begin
p:=1; d[p,1]:=x; d[p,2]:=y;
b[x,y]:=1; inc(all);
bfs(1,1);
end;

begin
init;
for i:=1 to 100 do
begin
 if ((a[i,0]=0)or(a[i-1,0]=0))and(b[i,1]=0) then main(i,1);
 if ((a[i,100]=0)or(a[i-1,100]=0))and(b[i,100]=0) then main(i,100);
 if ((a[0,i]=0)or(a[0,i-1]=0))and(b[1,i]=0) then main(1,i);
 if ((a[100,i]=0)or(a[100,i-1]=0))and(b[100,i]=0) then main(100,i);
end;
total:=10000-all;
write(f2,total);
close(f1); close(f2);
end.