Cod sursa(job #1275034)

Utilizator lokixdSebastian lokixd Data 24 noiembrie 2014 17:54:37
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <fstream>
#include <algorithm>
#include <limits>
using namespace std;
 
const int kMaxN = 1005, kMaxM = 1000005;
 
ifstream fin("trapez.in");
ofstream fout("trapez.out");
 
int N, M, x[kMaxN], y[kMaxN], sol;
double slope[kMaxM];
 
int main() {
    fin >> N;
    for (int i = 0; i < N; ++i) {
        fin >> x[i] >> y[i];
        for (int j = 0; j < i; ++j)
            slope[M++] = (x[i] == x[j]) ? numeric_limits<double>::infinity() : (1.0 * (y[j] - y[i]) / (x[j] - x[i]));
    }
    sort(slope, slope + M);
    for (int i = 1, crt = 0; i < M; ++i)
        if (slope[i - 1] == slope[i]) {
            ++crt;
            sol += crt;
        } else {
            crt = 0;
        }
    fout << sol << "\n";
    return 0;
}