Cod sursa(job #1167375)

Utilizator mvcl3Marian Iacob mvcl3 Data 4 aprilie 2014 21:13:44
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.71 kb
#include <fstream>
#include <vector>
#include <algorithm>

#define in "trapez.in"
#define out "trapez.out"
#define i64 long long

std :: ifstream f(in);
std :: ofstream g(out);

typedef std :: pair < i64, i64 > POINT;

class cmp  {
    public :
        bool operator () (const POINT &A, const POINT &B)   {
            if(A.first * B.second == A.second * B.first)    return 0;

            bool b = (A.first * B.second < A.second * B.first);

            if(B.second < 0 )    b = !b;
            if(A.second < 0 )    b = !b;

            return b;
        }
};

class Trapez {
    public :
        std :: vector < POINT > Get_Set_of_Slopes (std :: vector < POINT > P)   {
            std :: vector < POINT > Slopes;

            for(int i = 0; i < P.size() - 1; ++i)
                for(int j = i + 1; j < P.size(); ++j)   Slopes.push_back( { P[i].first - P[j].first, P[i].second - P[j].second } );

            return Slopes;
        }

        i64 Count (std :: vector < POINT > Slopes)  {
            std :: sort (Slopes.begin(), Slopes.end(), cmp());

            i64 nbr = 1, ans = 0;

            for(int i = 1; i < Slopes.size(); ++i)  {
                if(Slopes[i].first * Slopes[i - 1].second == Slopes[i].second * Slopes[i - 1].first)    ++nbr;
                else    {
                    ans += nbr * (nbr - 1) / 2;
                    nbr = 1;
                }
            }
            ans += nbr * (nbr - 1) / 2;

            return ans;
        }

};

int main() {
    int N;
    Trapez obj;

    f >> N;

    std :: vector < POINT > P(N);

    for(int i = 0; i < N; ++i)  f >> P[i].first >> P[i].second;
    std :: vector < POINT > Slopes = obj.Get_Set_of_Slopes(P);
    g << obj.Count(Slopes) << '\n';

    g.close();
    return 0;
}