thieumao

8 quân hậu 2

Sep 14th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.20 KB | None | 0 0
  1. Program TamQuanHau;
  2. Uses Crt;
  3. Type mang = array[1..8] of Integer;
  4. Var
  5.   x: mang;
  6.   a: array[1..8] of Boolean;
  7.   b: array[2..16] of Boolean;
  8.   c: array[-7..7] of Boolean;
  9.   i,j,k: Integer;
  10.   antoan: Boolean;
  11.  
  12. procedure print(m: mang);
  13. var k: Integer;
  14. begin
  15.   for k:=1 to 8 do write(m[k]);
  16.   writeln;
  17. end;
  18.  
  19. procedure try;
  20. begin
  21.   repeat
  22.     repeat
  23.       i:=i+1;
  24.       antoan:=a[i] and b[i+j] and c[i-j];
  25.     until antoan or (i=8);
  26.     if antoan then
  27.       begin
  28.         x[j]:=i;
  29.         a[i]:=false; b[i+j]:=false; c[i-j]:=false;
  30.         j:= j+1; i:= 0
  31.       end
  32.     else
  33.       begin
  34.         j:=j-1;
  35.         if j>=1 then
  36.           begin
  37.             i:=x[j];
  38.             a[i]:=true; b[i+j]:=true; c[i-j]:=true;
  39.             if i=8 then
  40.               begin
  41.                 j:=j-1;
  42.                 if j>=1 then
  43.                   begin
  44.                     i:=x[j];
  45.                     a[i]:=true; b[i+j]:=true; c[i-j]:=true
  46.                   end
  47.               end
  48.           end
  49.       end
  50.   until (j>8) or (j<1);
  51. end;
  52. Begin
  53.   clrscr;
  54.   for i:=1 to 8 do a[i]:=true;
  55.   for i:=2 to 16 do b[i]:=true;
  56.   for i:=-7 to 7 do c[i]:=true;
  57.   j:=1; i:=0;
  58.   try;
  59.   print(x);
  60.   readln;
  61. end.
Advertisement
Add Comment
Please, Sign In to add comment