about summary refs log tree commit diff
path: root/others/other/colorec.pas
blob: a6931aa262820834d37ce520de2b1946f6ad3837 (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
type
  pointtype = record
    x, y: int16
  end;

var
  f: text;
  n, i, j: int32;
  count: int32 = 0;
  c, k: int8;
  color: array[-200..200, -200..200] of int8;
  points: array[1..4, 1..100000] of pointtype;
  len: array[1..4] of int16 = (0, 0, 0, 0);

function colorec(var a, b: pointtype): boolean;
  begin
    colorec := [color[a.x, b.y], color[b.x, a.y],
                color[a.x, a.y], color[b.x, b.y]] = [1, 2, 3, 4]
  end;

begin
  for i := -200 to 200 do
    for j := -200 to 200 do
      color[i, j] := 0;
  assign(f, 'COLOREC.INP');
  reset(f);
  readln(f, n);
  repeat
    readln(f, i, j, c);
    color[i, j] := c;
    inc(len[c]);
    points[c, len[c]].x := i;
    points[c, len[c]].y := j
  until eof(f);
  close(f);

  for k := 1 to 4 do
    if len[k] <= n then
      begin
        c := k;
        n := len[c]
      end;
  for i := 1 to n do
    for k := 1 to 4 do
      if k <> c then
        for j := 1 to len[k] do
          if colorec(points[c, i], points[k, j]) then
            inc(count);

  assign(f, 'COLOREC.OUT');
  rewrite(f);
  writeln(f, count);
  close(f)
end.