Войти или зарегистрироваться
Выберите удобный способ — аккаунт создастся автоматически.
Или войдите по логину и паролю

29.11.2009, 14:45
|
|
Новичок
Регистрация: 09.03.2009
Сообщений: 5
С нами:
9038971
Репутация:
4
|
|
{--------------------------------------------------------------}
Program Blochi;
const
InpFile = 'input.txt';
Outfile = 'output.txt';
const
Max = 250;
type
Field = Array [-1..Max+2,-1..Max+2] of Byte;
Steps = array [1..8] of -2..2;
const
x:Steps = (-1,1,2,2,1,-1,-2,-2);
y:Steps = (-2,-2,-1,1,2,2,1,-1);
var
n,m,Yk,Xk,q:integer;
f:field;
procedure detectfield;
var
i,j,k,step:integer;
waschanges:boolean;
begin
fillchar(f,Sizeof(f),0);
for i:=1 to 8 do F[Yk+y[i],Xk+x[i]]:=1;
waschanges:=true;
step:=1;
while waschanges do begin
waschanges:=false;
for i:=1 to n do
for j:=1 to M do if f [i,j] = step then
for k:=1 to 8 do
if f[i+y[k],j+x[k]]=0 then begin
f[i+y[k],j+x[k]]:=step+1;
waschanges:=true;
end;
inc(step);
end;
f[yk,xk]:=0;
end;
Procedure initfield;
var
i,y2,x2:integer;
answer:longint;
nosolution:boolean;
begin
assign(input,inpfile);
reset(input);
assign(output,outfile);
rewrite(output);
answer:=0;
nosolution:=false;
read(n,m,yk,xk,q);
if q>0 then detectfield;
for i:=1 to q do begin
read(y2,x2);
if f [y2,x2]=0 then if (y2<>yk)or(x2<>xk) then nosolution:=true;
answer:=answer+f[y2,x2];
end;
if nosolution then writeln(-1)
else writeln(answer);
close(input);
close(output);
end;
begin
initfield;
end.
|
|
|
|
Предыдущая тема
Следующая тема
|
Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
|
|
|
|