Cod sursa(job #3185182)

Utilizator AnSeDraAndrei Sebastian Dragulescu AnSeDra Data 18 decembrie 2023 11:09:58
Problema Trapez Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <fstream>
#include <algorithm>

using namespace std;

const int Nmax = 1000;

struct punct{
    long long x, y;
};

punct v[Nmax];
long long pante[Nmax * Nmax];

int main(){
    ifstream fin("trapez.in");
    ofstream fout("trapez.out");

    int n, len, sol, cnt;

    fin >> n;
    for(int i = 0; i < n; i++){
        fin >> v[i].x >> v[i].y;
    }

    len = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            pante[len++] = v[i].y - v[j].y;
        }
    }

    sort(pante, pante + len);

    sol = 1;
    cnt = 1;
    for(int i = 1; i < len; i++){
        if(pante[i] == pante[i - 1]){
            cnt++;
        }
        else{
            if(cnt >= 2){
                sol += (cnt - 2) * (cnt - 1);
            }
            cnt = 0;
        }
    }

    fout << sol;

    return 0;
}