Cod sursa(job #2276569)

Utilizator DonCiprianoAmzuloiu Andrei-Ciprian DonCipriano Data 4 noiembrie 2018 21:22:52
Problema Trapez Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.19 kb
#include <fstream>

using namespace std;

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

float findM(point a, point b)
{
    return (float) (b.y - a.y) / (b.x - a.x);
}

int main()
{
    int noPoints;
    point p[1000];

    float m1;
    float m2;

    int noResults = 0;

    ifstream fin("trapez.in");

    fin >> noPoints;

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

    fin.close();

    for(int i = 0; i < noPoints; i++)
    {
        for(int j = i + 1; j < noPoints; j++)
        {
            //if(i == j) continue;

            m1 = findM(p[i], p[j]);

            for(int k = 0; k < noPoints; k++)
            {
                for(int l = k + 1; l < noPoints; l++)
                {
                    //if(k == l) continue;
                    if( (k == i && l == j) || (k == j && l == i)) continue;

                    m2 = findM(p[k], p[l]);

                    if(m1 == m2) noResults++;
                }
            }
        }
    }

    //noResults = (noResults - noPoints)/2;
    ofstream fout("trapez.out");
    fout << noResults / 2;
    fout.close();

    return 0;
}