Cod sursa(job #2761066)

Utilizator butasebiButa Gabriel-Sebastian butasebi Data 30 iunie 2021 13:27:33
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <iostream>
#include <fstream>
#include<algorithm>
#define INF 1000000000
using namespace std;
struct coordonate
{
    int x, y;
}v[1005];
double slope(coordonate A, coordonate B)
{
    if (B.x == A.x)return -INF;
    return double(B.y - A.y) / (B.x - A.x);
}
int i, j, n, nr_sol, nr_comp, k;
double sol[1000005];
int main()
{   
    ifstream f("trapez.in");
    ofstream g("trapez.out");
    f >> n;
    for (i = 1; i <= n; i++)
        f >> v[i].x >> v[i].y;
    for (i = 1; i < n; i++)
        for (j = i + 1; j <= n; j++)
            sol[++k] = slope(v[i], v[j]);
    sort(sol + 1, sol + k + 1);
    for (i = 2; i <= k; i++)
        if (sol[i] == sol[i - 1])nr_comp++;
        else
        {
            nr_sol = nr_sol + (nr_comp * (nr_comp - 1)) / 2;
            nr_comp = 1;
        }
    nr_sol = nr_sol + (nr_comp * (nr_comp - 1)) / 2;
    g << nr_sol;
    return 0;
}