Cod sursa(job #2626014)

Utilizator CoakazeRotaru Catalin Coakaze Data 6 iunie 2020 11:26:08
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

struct punct
{
    int x,y;
} p[1001];

long double m[1000001];

int main()
{
    ifstream f("trapez.in");
    ofstream g("trapez.out");
    int n, nr = 0, x, y;
    int nt = 0;
    f>>n;
    for(int i=1; i<=n; i++)
    {
        f>>x>>y;
        p[i].x = x;
        p[i].y = y;
    }
    for(int i=1; i<n; i++)
        for(int j=i+1; j<=n; j++)
        {
            nr++;
            m[nr] = (1.0*(p[j].y-p[i].y))/(1.0*(p[j].x-p[i].x));
        }
    sort(m + 1, m + nr + 1);
    int i=1, j;
    while(i <= nr)
    {
        j = i;
        while(m[i] == m[j])
            j++;
        if(j - i > 1)
            nt += ((j - i) * (j - i - 1))/2;
        i = j - 1;
        i++;
    }
    g<<nt;
    return 0;
}