Cod sursa(job #997961)

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

const int NMAX = 1005;
const double EPS = 1e-6, INF = 1.0 * 0x3f3f3f3f;

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 <= N; ++ j)
            if(X[i] == X[j])
                Slope.push_back(INF);
            else
                Slope.push_back((1.0 * (Y[i] - Y[j])) / (1.0 * (X[i] - X[j])));

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

    int Cnt = 1;
    for(int i = 1; i < Slope.size(); ++ i)
        if(fabs(Slope[i] - Slope[i - 1]) < EPS)
            Cnt ++;
        else
        {
            Ans += (Cnt * (Cnt - 1)) / 2;
            Cnt = 1;
        }
    Ans += (Cnt * (Cnt - 1)) / 2;

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

    return 0;
}