记录编号 |
7466 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[BYVoid S1] 血色叛徒 |
最终得分 |
100 |
用户昵称 |
辨机ZN |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.491 s |
提交时间 |
2008-11-10 14:36:29 |
内存使用 |
3.47 MiB |
显示代码纯文本
program ex(f1,f2);
type
zn=array [0..505,0..505] of boolean;
ka=array [1..501,1..501] of longint;
fa=array [0..250001] of longint;
da=record
x,y:integer;
end;
la=array [1..250050] of da;
var
flag,flag2:zn;
d:ka;
c:fa;
a:la;
f1,f2:text;
i,j,k,m,p,l,ans,tot,xx,yy,n1,n2,x1,y1:longint;
head,tail,wei:longint;
procedure bfs(left,right:longint);
var
i,j,k,p:longint;
begin
for i:=head to tail do
begin
if flag2[a[i].x,a[i].y] then
begin
inc(tot);
c[d[a[i].x,a[i].y]]:=ans;
end;
if (a[i].x-1>=1)and(flag[a[i].x-1,a[i].y]=false) then
begin
flag[a[i].x-1,a[i].y]:=true;
inc(wei);
a[wei].x:=a[i].x-1; a[wei].y:=a[i].y;
end;
if (a[i].y-1>=1)and(flag[a[i].x,a[i].y-1]=false) then
begin
flag[a[i].x,a[i].y-1]:=true;
inc(wei);
a[wei].x:=a[i].x; a[wei].y:=a[i].y-1;
end;
if (a[i].x+1<=xx)and(flag[a[i].x+1,a[i].y]=false) then
begin
flag[a[i].x+1,a[i].y]:=true;
inc(wei);
a[wei].x:=a[i].x+1; a[wei].y:=a[i].y;
end;
if (a[i].y+1<=yy)and(flag[a[i].x,a[i].y+1]=false) then
begin
flag[a[i].x,a[i].y+1]:=true;
inc(wei);
a[wei].x:=a[i].x; a[wei].y:=a[i].y+1;
end;
end;
end;
begin
assign(f1,'crusade.in'); reset(f1);
assign(f2,'crusade.out'); rewrite(f2);
readln(f1,xx,yy,n1,n2);
tail:=0;
for i:=1 to n1 do
begin
readln(f1,x1,y1);
flag[x1,y1]:=true;
inc(tail);
a[tail].x:=x1; a[tail].y:=y1;
end;
for i:=1 to n2 do
begin
readln(f1,x1,y1);
flag2[x1,y1]:=true;
d[x1,y1]:=i;
end;
head:=1; wei:=tail; tot:=0; ans:=0;
while tot<n2 do
begin
bfs(head,tail);
inc(ans);
head:=tail+1;
tail:=wei;
end;
for i:=1 to n2 do
writeln(f2,c[i]);
close(f1);
close(f2);
end.