Cod sursa(job #1993401)

Utilizator Debuger33Numarul1 Debuger33 Data 22 iunie 2017 21:00:58
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <iostream>
#include <set>
#include <vector>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <unordered_map>
using namespace std;

int n;
pair<int, int> v[1000 + 10];

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

unordered_map<double, int> u;

double panta(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second) {
        return (double)(a.first - b.first) / (double) (a.second - b.second);
    }
    return (double) (1 << 30);
}

void read() {
    long long result = 0;
    fin >> n;
    for(int i = 1; i <= n; i++) {
        fin >> v[i].first >> v[i].second;
    }
    fin.close();
    for(int i = 1; i <= n; i++) {
        for(int j = i + 1; j <= n; j++) {
            u[panta(v[i], v[j])]++;
        }
    }
    for(auto it = u.begin(); it != u.end(); it++) {
        int val = it -> second;
        result += (1LL * val * (val - 1)) / 2;
    }
    fout << result << endl;
    fout.close();
}

int main() {
    read();
    return 0;
}