2 way
: array [1..8,1..2] of longint=((-2,-1),(-2,1),(-1,2),(1,2),
3 (2,1),(2,-1),(1,-2),(-1,-2));
5 a
: array [-1..150,-1..150] of char;
6 queue
: array [0..100000] of record
9 father
: array [0..100000] of longint;
13 i
,j
,m
,n
,head
,tail
,ans
: longint;
15 function check(x
,y
: longint):boolean;
18 if (a
[x
,y
]='.') then exit(true);
28 if a
[i
,j
]='K' then begin queue
[1].x
:=i
; queue
[1].y
:=j
; a
[i
,j
]:='.'; end;
29 if a
[i
,j
]='H' then begin endqueue
.x
:=i
; endqueue
.y
:=j
; a
[i
,j
]:='.'; end;
38 if check(queue
[head
].x
+way
[i
,1],queue
[head
].y
+way
[i
,2]) then
41 queue
[tail
].x
:=queue
[head
].x
+way
[i
,1];
42 queue
[tail
].y
:=queue
[head
].y
+way
[i
,2];
44 if (queue
[tail
].x
=endqueue
.x
) and (queue
[tail
].y
=endqueue
.y
) then break
;