Cod sursa(job #2916115)

Utilizator alin.gabrielAlin Gabriel Arhip alin.gabriel Data 28 iulie 2022 08:15:13
Problema Trapez Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <fstream>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef long double ld;

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

    int n;
    ll x[1000], y[1000], s = 0, xd;
    unordered_map<ld, ll> um;
    fin >> n;
    for (int i = 0; i < n; i++) {
        fin >> x[i] >> y[i];
        for (int j = 0; j < i; j++) {
            xd = x[j] - x[i];
            if (xd != 0)
                s += um[(ld)(y[j] - y[i]) / xd]++;
            else 
                s += um[-1]++;
            
        }
    }

    fout << s;
    fin.close();
    fout.close();
    return 0;
}