Cod sursa(job #2551367)

Utilizator bluestorm57Vasile T bluestorm57 Data 19 februarie 2020 19:40:33
Problema Trapez Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("trapez.in");
ofstream g("trapez.out");

const int NMAX = 1005;
const int inf = 1e9;
const double ihopeno = 0.000000001;
vector < double > slope;
pair < int, int > v[NMAX];
int n,ans;

double ecu(const pair < int, int > &Y, const pair < int, int > &X){
    if(X.first == Y.first)
        return inf;
    return (double(X.second - Y.second) / double(X.first - Y.first));
}

bool equality(double &X, double &Y){
    return (abs(X - Y) < ihopeno);
}

int main(){
    int i,j;
    double x;
    f >> n;
    for(i = 1 ; i <= n ; i++){
        f >> v[i].first >> v[i].second;
        for(j = i - 1 ; j >= 1 ; j--){
            x = ecu(v[i], v[j]);
            slope.push_back(x);
        }
    }

    sort(slope.begin(), slope.end());

    int leng = 0;
    for(i = 1 ; i < slope.size() ; i++){
        if(equality(slope[i], slope[i - 1]))
            leng++;
        else{
            ans += leng * (leng - 1) / 2;
            leng = 1;
        }
    }
    ans += leng * (leng - 1) / 2;
    g << ans;

    return 0;
}