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
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
#include <iostream>

using namespace std;

int main() {

    int n, a = 0;
    int* tab1, * tab2, * tab3;

    cin >> n;

    tab1 = new int[n];
    tab2 = new int[n];
    tab3 = new int[n];

    for (int i = 0; i < n; i++) {
        cin >> tab1[i] >> tab2[i] >> tab3[i];
        if (tab1[i] == 2) {
            a++;
        }
    }
    int* tab4;
    int* tab5;
    tab4 = new int[n - a];
    tab5 = new int[a];
    int* tab6;
    int* tab7;
    tab6 = new int[n - a];
    tab7 = new int[a];
    int* zderzeniapionowe;
    int* zderzeniapoziome;
    zderzeniapionowe = new int[n - a];
    zderzeniapoziome = new int[a];

    for (int i = 0; i < n; i++) {
        if (i < n - a) {
            zderzeniapionowe[i] = 0;
        }
        if (i < a) {
            zderzeniapoziome[i] = 0;
        }
    }

    a = 0;
    int b = 0;

    for (int i = 0; i < n; i++) {
        if (tab1[i] == 1) {
            tab4[a] = tab2[i];
            tab6[a] = tab3[i];
            a++;
        }
        else {
            tab5[b] = tab2[i];
            tab7[b] = tab3[i];
            b++;
        }
    }
    delete[] tab1;
    delete[] tab2;
    delete[] tab3;

    for (int i = 0; i < n - a; i++) {
        for (int j = 0; j < a; j++) {
            if (tab4[i] - tab6[i] == tab5[j] - tab7[j]) {
                zderzeniapionowe[i]++;
                zderzeniapoziome[j]++;
            }
        }
    }

    delete[] tab4;
    delete[] tab5;
    delete[] tab6;
    delete[] tab7;

    int pionowe = 0;
    int poziome = 0;
    for (int i = 0; i < n - a; i++) {
        if (zderzeniapionowe[i] > 0) {
            for (int j = i; j < n - a; j++) {
                zderzeniapionowe[j] = 0;
            }
            pionowe++;
        }
    }
    for (int i = 0; i < a; i++) {
        if (zderzeniapoziome[i] > 0) {
            for (int j = i; j < a; j++) {
                zderzeniapoziome[j] = 0;
            }
            poziome++;
        }
    }

    delete[] zderzeniapionowe;
    delete[] zderzeniapoziome;

    if (poziome > pionowe) {
        cout << pionowe << endl;
    }
    else {
        cout << poziome << endl;
    }

    return 0;
}