2: Inc(c,k);
-1: Inc(h,k);
-2: Dec(c,k);
End;
d2.hg:=h; d2.cot:=c;
End;
Function kt(Var d1,d2:diem):boolean;
Var g1,g,g2:diem;
k,p:integer;
Begin
kt:=true;
k:=(dlt-1) div 2;
p:=2 div abs(hgdi);
sinh(dmay,g1,-hgdi,k);
sinh(dmay,g2,-hgdi,2*k);
sinh(g1,g,p,k);
sinh(dmay,d1,p,k);
sinh(g2,d2,p,k);
If (A[d1.hg,d1.cot]='.')and(A[g.hg,g.cot]='.')and(A[d2.hg,d2.cot]='.')then
begin A[g.hg,g.cot]:='x'; HienA(-10,10,-10,10); exit; end;
sinh(g1,g,-p,k);
sinh(dmay,d1,-p,k);
sinh(g2,d2,-p,k);
kt:=false;
Procedure Ngdi;
Repeat
Write('Nhap toa do diem (hang,cot): '); Readln(dng.hg,dng.cot);
Until
(dng.hg>=Min)and(dng.hg<=Max)and(dng.cot>=Min)and(dng.cot<=Max)and(A[dng.hg,dng.cot]='.');
A[dng.hg,dng.cot]:='1'; HienA(-10,10,-10,10);
Function Hgchan:Integer;
Var Hgc:Integer;
Begin
If dmay.cot<dng.cot then
Hgc:=2;
If Hgc=hgdi then Begin Hgchan:=Hgc; Exit; End;
End;
If dmay.cot>dng.cot then
Hgc:=-2;
If dmay.hg<dng.hg then
Hgc:=-1;
If dmay.hg>dng.hg then
Hgc:=1;
Hgchan:=Hgc;
Procedure Nap(Var Q:Qu; d1:diem; hgdi,k:Integer);
Var h,c:Integer;
d2:diem;
Sinh(d1,Q[cq],hgdi,k);
Procedure Maydi;
Inc(dq);
if not ok then
Begin
If Q[dq].hg<dmay.hg then hgdi:=1
Else If Q[dq].hg>dmay.hg then hgdi:=-1
Else If Q[dq].cot<dmay.cot then hgdi:=-2
Else If Q[dq].cot>dmay.cot then hgdi:=2;
End;
dmay:=Q[dq];
A[q[dq].hg,q[dq].cot]:='x';
HienA(-10,10,-10,10)
Procedure Process;
Var Hgc,p,i,ntt:Integer;
ok:=true; ntt:=0;
Ngdi;
Hgc:=Hgchan; Hgdi:=-Hgc;
Inc(cq); Nap(Q,dmay,hgdi,1); Maydi; Inc(dlt);
Repeat
Ngdi; Hgc:=Hgchan;
If ntt=1 then
If A[dc1.hg,dc1.cot]='.' then finish(dc1)
Else finish(dc2);
If ntt=0 then If (dlt>=3) and (kt(dc1,dc2)) then ntt:=1;
If (Hgc=Hgdi) then
If ok then
Begin
p:=2 div abs(Hgc);
For i:=1 to dlt-1 do
Begin
Inc(cq); Nap(Q,dmay,p,i); Nap(Qc,Q[cq],-hgdi,i);
Inc(cq); Nap(Q,dmay,-p,i);Nap(Qc,Q[cq],-hgdi,i);
End;
ok:=false;
dlt:=1;
End
Else
hgdi:=-hgdi; Inc(cq); Nap(Q,dmay,hgdi,dlt);
End;
If ntt=0 then
If dq=cq then Begin Inc(cq); Nap(Q,dmay,hgdi,1); End;
If A[Qc[dq].hg,Qc[dq].cot]='.' then finish(Qc[dq]);
Maydi; Inc(dlt);
Until fin;
BEGIN
Init;
Process;
END.
Bạn đang xem 2: - 100 DE TIN HSG CO DAP AN