Cod sursa(job #2047724)

Utilizator CiprianC11Constantinescu Ciprian CiprianC11 Data 25 octombrie 2017 10:30:28
Problema Trapez Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <cstdio>
#include <cmath>
#include <vector>

using namespace std;

const double eps = 1.e-14;

struct po
{
    int x;
    int y;
};

vector <po>v;
vector <double>p;

bool vertical(po p1, po p2)
{
    return p1.x == p2.x;
}

double panta(po p1, po p2)
{
    if(vertical(p1, p2)) return 2.e9;
    return (1.0 * p2.y - p1.y)/(p2.x - p1.x);
}

int main()
{
    freopen("trapez.in", "r", stdin);
    freopen("trapez.out", "w", stdout);
    int n, x, y, cnt = 0;
    po tmp;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%d%d", &x, &y);
        tmp.x = x;
        tmp.y = y;
        v.push_back(tmp);
    }
    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            if(panta(v[i], v[j]) != 2.e9) p.push_back(panta(v[i], v[j]));
        }
    }
    for(int i = 0; i < p.size(); i++)
    {
        for(int j = i + 1; j < p.size(); j++)
        {
            if(fabs(p[i] - p[j]) < eps)
            {
                cnt++;
            }
        }
    }
    printf("%d", cnt);
    return 0;
}