Cod sursa(job #761883)

Utilizator SteveStefan Eniceicu Steve Data 27 iunie 2012 18:32:13
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <fstream>
#include <algorithm>
#include <iostream>

using namespace std;

#define INF 2000000010

typedef struct {
    int x;
    int y;
} coord;

int N;
coord v[1010];
double panta[1000010];

void Citire () {
    ifstream fin ("trapez.in");
    fin >> N;
    for (int i = 0; i < N; i++)
    {
        fin >> v[i].x >> v[i].y;
    }
    fin.close ();
}

int Business () {
    int lol = -1;
    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            if (v[i].x == v[j].x) panta[++lol] = INF;
            else
            {
                if (v[i].y == v[j].y) panta[++lol] = 0;
                else panta[++lol] = ((double) v[j].y - v[i].y) / ((double) v[j].x - v[i].x);
            }
        }
    }
    sort (panta, panta + lol + 1);
    int cate = 0, S = 0;
    for (int i = 1; i <= lol; i++)
    {
        if (panta[i] == panta[i - 1]) cate++;
        else S += (cate * (cate - 1)) >> 1, cate = 1;
    }
    S += (cate * (cate - 1)) >> 1;
    return S;
}

void Scriere () {
    ofstream fout ("trapez.out");
    fout << Business ();
    fout.close ();
}

int main ()
{
    Citire ();
    Scriere ();
    return 0;
}