Cod sursa(job #963424)

Utilizator CosminRusuCosmin Rusu CosminRusu Data 17 iunie 2013 14:10:26
Problema Trapez Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
/// !TRAPEZ - it's chest day :)

#include <fstream>
#include <vector>
#include <algorithm>

#define x first
#define y second

using namespace std;

const int DN = 1005;

pair<int, int> points[DN];
double slope[DN];
int n, slopes;
int Answer;

int main()
{
    ifstream cin("trapez.in");
    ofstream cout("trapez.out");

    cin >> n;
    for(int i = 1 ; i <= n ;++ i)
    {
        cin >> points[i].x >> points[i].y;
        for(int j = 1 ; j < i ; ++ j)
            slope[++slopes] = (double)(points[j].first - points[i].first) / (points[j].second - points[i].second);
    }

    stable_sort(slope + 1, slope + slopes + 1);
    for(int i = 1 ; i <= slopes; ++ i)
    {
        int nr = 1;
        while( i + 1 <= slopes && slope[i] == slope[i+1] )
        {
            ++ nr;
            ++ i;
        }
        Answer += (nr*(nr-1))/2;
    }
    cout << Answer << "\n";
    return 0;
}