Cod sursa(job #1802843)

Utilizator alexkolumeRadulescu Ioan-Alexandru alexkolume Data 10 noiembrie 2016 17:56:07
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

struct punct
{
    int x, y;
};


int main()
{
    punct p[1001];
    ifstream fin("trapez.in");

    int i, j, n, x, y, numarator, numitor, nrtrapeze;
    nrtrapeze = 0;
    double jeg;
    vector <double> pante;
    fin >> n;

    for(i = 0; i < n; i++)
    {
        fin >> p[i].x;
        fin >> p[i].y;
    }
    fin.close();


    for(i = 0; i < n; i ++)
        for(j = i + 1; j < n; j ++)
    {
        numarator = p[j].y - p[i].y;
        numitor = p[j].x - p[i].x;
        if(numitor == 0)
            pante.push_back(1000000);
        else
        {
            jeg = (double)numarator / (double)numitor;
            pante.push_back(jeg);
        }
    }

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

    i = 0;
    while (i < pante.size())
    {
        j = i + 1;
        while(pante[j] == pante[j - 1] && j < pante.size())
            j++;
        nrtrapeze += (j - i) * (j - i - 1) / 2;
        i = j;
    }


    ofstream fout("trapez.out");
    fout << nrtrapeze;
    fout.close();
    return 0;
}