Cod sursa(job #1821572)

Utilizator ionutpop118Pop Ioan Cristian ionutpop118 Data 3 decembrie 2016 12:38:28
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <cstdio>
#include <algorithm>
using namespace std;
const double eps = 1.e-14;
const int INF = 1232424242;
struct point
{
    int x, y;
};
point v[1005];
double p[1000005];
inline double panta(point a, point b)
{
    if (a.y == b.y)
        return INF;
    return ((double) a.x - b.x) / ((double) a.y - b.y);
}
bool cmp(double a, double b)
{
    return (a - b) < eps;
}
int main()
{
    freopen("trapez.in", "r", stdin);
    freopen("trapez.out", "w", stdout);

    int n, x, y, k, l, ans;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
    {
        scanf("%d %d", &x, &y);
        v[i].x = x; v[i].y = y;
    }

    k = 0;
    for (int i = 1; i < n; ++i)
        for (int j = i + 1; j <= n; ++j)
            p[++k] = panta(v[i], v[j]);

    sort (p + 1, p + k + 1, cmp);

    l = 1; ans = 0;
    for (int i = 2; i <= k; ++i)
    {
        if (p[i] - p[i - 1] < eps)
            ++l;
        else
        {
            ans += l * (l - 1) / 2;
            l = 1;
        }
    }
    ans += l * (l - 1) / 2;
    printf("%d\n", ans);
    return 0;
}