记录编号 |
7065 |
评测结果 |
WWWWWWEEWA |
题目名称 |
[USACO Dec08] 花园栅栏 |
最终得分 |
10 |
用户昵称 |
maxiem |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
0.112 s |
提交时间 |
2008-11-06 10:57:05 |
内存使用 |
0.17 MiB |
显示代码纯文本
program fence;
const d:array [1..4,1..2] of shortint=((0,1),(0,-1),(1,0),(-1,0));
var
table:array [-1..101,-1..101] of record
already:boolean;
wall:array [1..4] of boolean;
end;
step:array [1..1000] of record
dir,pace:integer;
end;
s:string;
i,j,sum,code,z,x,y:integer;
procedure go(x,y:byte);
var i:byte;
begin
if table[x,y].already<>true then begin
inc(sum);table[x,y].already:=true;
for i:=1 to 4 do if (x+d[i,1]>=0) and (x+d[i,1]<=100) and (y+d[i,2]>=0) and (y+d[i,2]<=100) then
if table[x,y].wall[i]<>true then go(x+d[i,1],y+d[i,2]);
end
end;
begin
fillchar (table,sizeof(table),0);
assign (input,'fence.in');
reset (input);
readln (x,y,z);
for i:=1 to z do begin
readln (s);
if copy(s,1,1)='N' then step[i].dir:=3;
if copy(s,1,1)='E' then step[i].dir:=1;
if copy(s,1,1)='S' then step[i].dir:=4;
if copy(s,1,1)='W' then step[i].dir:=2;
val(copy(s,3,length(s)-2),step[i].pace,code);
end;
close (input);
assign (output,'fence.out');
rewrite (output);
for i:=1 to z do begin
for j:=1 to step[i].pace do begin
if step[i].dir in [1..2] then begin
table[x,y].wall[4]:=true;
table[x,y].wall[3]:=true;
table[x-1,y].wall[3]:=true;
table[x+1,y].wall[4]:=true;
end
else begin
table[x,y].wall[1]:=true;
table[x,y].wall[2]:=true;
table[x,y-1].wall[1]:=true;
table[x,y+1].wall[2]:=true;
end;
inc(x,d[step[i].dir,1]);
inc(y,d[step[i].dir,2]);
end;
dec(x,d[step[i].dir,1]);
dec(y,d[step[i].dir,2]);
end;
sum:=0;
for i:=0 to 100 do if table[0,i].wall[4]=false then go(0,i);
for i:=0 to 100 do if table[100,i].wall[3]=false then go(100,i);
for i:=0 to 100 do if table[i,0].wall[2]=false then go(i,0);
for i:=0 to 100 do if table[i,100].wall[1]=false then go(i,100);
sum:=101*101-sum;
writeln (sum);
close (output);
end.