Cod sursa(job #997967)

Utilizator poptibiPop Tiberiu poptibi Data 15 septembrie 2013 12:42:17
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

const int NMAX = 1005;
const double EPS = 1e-3, INF = 1.0 * (1 << 30);

int N, X[NMAX], Y[NMAX], Ans;
vector<double> Slope;

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

    scanf("%i", &N);
    for(int i = 1; i <= N; ++ i)
        scanf("%i %i", &X[i], &Y[i]);

    for(int i = 1; i <= N; ++ i)
        for(int j = i - 1; j >= 1; -- j)
            if(X[i] == X[j])
                Slope.push_back(INF);
            else
                Slope.push_back(1.0 * (1.0 * (Y[i] - Y[j])) / (1.0 * (X[i] - X[j])));

    sort(Slope.begin(), Slope.end());

    for(int i = 0; i < Slope.size(); )
    {
        int Cnt = 0, Start = i;
        while(i < Slope.size() && Slope[i] == Slope[Start])
            Cnt ++, i ++;
        Ans += (Cnt * (Cnt - 1)) / 2;
    }

    printf("%i\n", Ans);

    return 0;
}