Cod sursa(job #2047694)

Utilizator PruteanuTheoPruteanu Theodor PruteanuTheo Data 25 octombrie 2017 10:01:39
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.19 kb
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

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

struct POINT{
    int x,y;
};

vector <double> pant;
vector <POINT> points;

bool vertical(POINT P1, POINT P2)
{
    return fabs(P1.x-P2.x)<eps;
}

double panta(POINT P1, POINT P2)
{
    if(vertical(P1,P2))
        return INF;
    return (1.0*P2.y-P1.y)/(P2.x-P1.x);
}

int main()
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    int n;
    POINT P;
    scanf("%d",&n);
    for(int y=1;y<=n;++y)
    {
        scanf("%d%d",&P.x,&P.y);
        points.push_back(P);
    }
    double aux;
    for(int i=0;i<points.size()-1;++i)
        for(int j=i+1;j<points.size();++j)
        {
            aux=panta(points[i],points[j]);
            pant.push_back(aux);
        }
    sort(pant.begin(),pant.end());
    int l=1;
    int sol=0;
    for(int i=1;i<pant.size();++i)
    {
        if(fabs(pant[i]-pant[i-1])<eps)
            l++;
        else
        {
            sol+=(l*(l-1))/2;
            l=1;
        }
    }
    sol+=(l*(l-1))/2;
    printf("%d",sol);
    return 0;
}