about summary refs log tree commit diff
path: root/2ndary/12/TP-HN-2010/_BAI3.pas
blob: 09ec0ca951667fcdb5b638be45193043e79b67d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
type
  board = array[0..1023] of boolean;

var
  f : text;
  a : board;
  i, j, k, l, m, n : byte;

function king(
  e : board;
  x, y : byte
) : board;
  var z, t : byte;
  begin
    for z := x - 1 to x + 1 do
      for t := y - 1 to y + 1 do
        e[z, t] := true;
    exit(e)
  end;

function full(c : board) : boolean;
  var d : boolean;
  begin
    for d in c do
      if not(d) then
        exit(false);
    exit(true)
  end;

function libai3(
  b : board;
  x0, y0 : byte
) : byte;
  type tmp = record
      n, x, y : byte
    end;
  var
    max : tmp;
    t, x, y : byte;
  begin
    if full(b) then exit(0);
    max.n := 0;
    for x := x0 to m do
      for y := y0 to n do
        if not(b[x, y]) then
          begin
            t := libai3(king(b, x, y), x + 1, y + 1) + 1;
            writeln(t);
            if t > max.n then
              begin
                max.x := x;
                max.y := y;
                max.n := t
              end
          end;
    exit(max.n)
  end;

begin
  assign(f, 'BAI3.INP');
  reset(f);
  readln(f, m, n, k);
  for l := 1 to k do
    begin
      readln(f, i, j);
      a := king(a, i, j)
    end;
  close(f);
  assign(f, 'BAI3.OUT');
  rewrite(f);
  writeln(libai3(a, 1, 1));
  close(f)
end.