Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program Dq;
- Uses crt;
- Const
- InputFile = 'DQ.INP';
- OutputFile = 'DQ.OUT';
- Var
- f: Text;
- A: Array [1..100,1..100] of Integer;
- X, Y: Array [1..4] of Integer;
- G, H: Array [1..10000] of Integer;
- S: Array [1..10000] of String;
- n, m, count: Integer;
- Procedure Input;
- Var
- i, j: Integer;
- Begin
- Assign(f,InputFile);
- Reset(f);
- Readln(f,n,m);
- count:=0;
- X[1]:=-1; X[2]:=0; X[3]:=1; X[4]:=0;
- Y[1]:=0; Y[2]:=1; Y[3]:=0; Y[4]:=-1;
- For i:=1 to n do
- Begin
- For j:=1 to m do
- Read(f,A[i,j]);
- Readln(f);
- End;
- Close(f);
- End;
- Procedure Output(v: Integer);
- Var
- i: Integer;
- Begin
- Assign(f,OutputFile);
- Rewrite(f);
- For i:=1 to v do
- Writeln(f,G[i],' ',H[i],' ',S[i]);
- Close(f);
- Halt;
- End;
- Procedure Go(v: Integer);
- Var
- i, j, k: Integer;
- Begin
- If Count=1 then Output(v)
- else
- For i:=1 to n do
- For j:=1 to m do
- If A[i,j]=1 then
- For k:=1 to 4 do
- If (i+2*X[k]>=1) and (j+2*Y[k]>=1) and (i+2*X[k]<=n) and (j+2*Y[k]<=m) then
- If (A[i+X[k],j+Y[k]]=1) and (A[i+2*X[k],j+2*Y[k]]=0) then
- Begin
- A[i,j]:=0;
- A[i+X[k],j+Y[k]]:=0;
- A[i+2*X[k],j+2*Y[k]]:=1;
- dec(count);
- G[v]:=i;
- H[v]:=j;
- Case k of
- 1: S[v]:='Up';
- 2: S[v]:='Right';
- 3: S[v]:='Down';
- 4: S[v]:='Left';
- End;
- Go(v+1);
- A[i,j]:=1;
- A[i+X[k],j+Y[k]]:=1;
- A[i+2*X[k],j+2*Y[k]]:=0;
- inc(count);
- End;
- End;
- Procedure Process;
- Var
- i, j: Integer;
- Begin
- For i:=1 to n do
- For j:=1 to m do
- If A[i,j]=1 then inc(count);
- Go(1);
- End;
- Begin
- Input;
- Process;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement