记录编号 |
6671 |
评测结果 |
AWWTWWEEWA |
题目名称 |
[USACO Dec08] 花园栅栏 |
最终得分 |
20 |
用户昵称 |
苏轼 |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
1.328 s |
提交时间 |
2008-11-03 22:28:44 |
内存使用 |
0.13 MiB |
显示代码纯文本
program cch(input,output);
const
xx:array[1..4] of integer=(1,0,-1,0);
yy:array[1..4] of integer=(0,1,0,-1);
chencch=110;
var
i,j,l,n,ans,x,y,x1,y1,k:integer;
ch:char;
area:array[0..900] of integer;
b:array[0..900] of boolean;
a:array[0..chencch,0..chencch] of integer;
flag:boolean;
procedure floodfill(x,y,color:integer);
var
i:integer;
begin
inc(area[color]);
a[x,y]:=color;
for i:=1 to 4 do
begin
x1:=x+xx[i];
y1:=y+yy[i];
if (x1>=0)and(x1<=chencch)and(y1>=0)and(y1<=chencch) then
if a[x1,y1]=0 then
floodfill(x1,y1,color);
end;
end;
begin
assign(input,'fence.in');
assign(output,'fence.out');
reset(input);
rewrite(output);
readln(x,y,n);
for i:=0 to chencch do
for j:=0 to chencch do a[i,j]:=0;
a[x,y]:=-1;
for i:=1 to n do
begin
readln(ch,l);
case ch of
'N':for j:=1 to l+1 do
begin
inc(x);
a[x,y]:=-1;
end;
'E':for j:=1 to l+1 do
begin
inc(y);
a[x,y]:=-1;
end;
'S':for j:=1 to l+1 do
begin
dec(x);
a[x,y]:=-1;
end;
'W':for j:=1 to l+1 do
begin
dec(y);
a[x,y]:=-1;
end;
end;
end;
area[0]:=0;
for i:=0 to chencch do
for j:=0 to chencch do
if a[i,j]=0 then
begin
inc(area[0]);
floodfill(i,j,area[0]);
end;
for i:=1 to area[0] do b[i]:=true;
for i:=0 to chencch do
begin
if a[0,i]<>-1 then b[a[0,i]]:=false;
if a[chencch,i]<>-1 then b[a[chencch,i]]:=false;
if a[i,0]<>-1 then b[a[i,0]]:=false;
if a[i,chencch]<>-1 then b[a[i,chencch]]:=false;
end;
ans:=0;
for i:=1 to area[0] do
if b[i] then
inc(ans,area[i]);
for i:=1 to chencch-1 do
for j:=1 to chencch-1 do
if a[i,j]=-1 then
begin
flag:=true;
for k:=1 to 4 do
begin
x1:=i+xx[k]; y1:=j+yy[k];
if (a[x1,y1]<>-1) and not b[a[x1,y1]] then
flag:=false;
end;
if flag then inc(ans);
end;
write(ans);
close(input);
close(output);
end.