Cod sursa(job #1279201)

Utilizator gabrielinelusGabriel-Robert Inelus gabrielinelus Data 29 noiembrie 2014 21:50:19
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.46 kb
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;
int N;
vector<pair<int,int> > Pct;

#define x first
#define y second

struct dreapta{
    pair<long long, long long> st;
    pair<long long, long long> dr;
    double oha;
    dreapta(pair<long long,long long> A,pair<long long,long long> B){
        if(A > B) swap(A,B);
        st = A;
        dr = B;
    }
};
vector<dreapta> dr;

void read()
{
    scanf("%d",&N);
    int x,y;
    for(int i = 1; i <= N; ++i)
    {
        scanf("%d%d",&x,&y);
        Pct.push_back(make_pair(x,y));
    }
}

class cmp{
public:
    bool operator()(const dreapta &d1 ,const dreapta &d2) const
    {
        return (d1.dr.y - d1.st.y) * (d2.dr.x - d2.st.x) < (d2.dr.y - d2.st.y) * (d1.dr.x - d1.st.x);
    }
};

bool egal( dreapta d1, dreapta d2)
{
    return (d1.dr.y - d1.st.y) * (d2.dr.x - d2.st.x) == (d2.dr.y - d2.st.y) * (d1.dr.x - d1.st.x);;
}

void solve()
{
    for(int i = 0; i < N; ++i)
        for(int j = 0; j < i; ++j)
            dr.push_back(dreapta(Pct[i],Pct[j]));
    sort(dr.begin(),dr.end(),cmp());

    int crt = 0,sol = 0;
    for(int i = 1; i < dr.size(); ++i)
        if(egal(dr[i],dr[i-1])){
            ++crt;
            sol += crt;
        }
        else
            crt = 0;
    printf("%d\n",sol);
}

int main()
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);

    read();
    solve();

    return 0;
}