Cod sursa(job #1981437)

Utilizator filipangAngheluta Filip filipang Data 15 mai 2017 18:38:10
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

const double eps = 1.e-14;
const double inf = 2.e9;

struct POINT{
    double x;
    double y;
};

double panta(POINT A, POINT B){
    if(fabs(A.x - B.x)<eps)return inf;
    return((B.y - A.y)/(B.x-A.x));
}

int main()
{
    ifstream in("trapez.in");
    ofstream out("trapez.out");
    int n;
    in >> n;
    vector<POINT> v;
    vector<double>pv;

    for(int i = 1; i <= n; i++){
        POINT p;
        in >> p.x >> p.y;
        v.push_back(p);
    }
    for(int i = 1; i <= v.size(); i++){
        for(int j = i; j <= v.size(); j++){
            pv.push_back(panta(v[i],v[j]));
        }
    }
    sort(pv.begin(), pv.end());
    int trapeze = 0;
    int nop = 0;
    for(int i = 1; i < pv.size(); i++){
        //out << pv[i] << endl;
        if(pv[i+1] == pv[i]){
            nop++;
        }
        else{
            if(nop!=0)
            trapeze = trapeze + nop*(nop+1)/2;
            nop = 0;
        }
    }
    out << trapeze;
    return 0;
}