Cod sursa(job #676729)

Utilizator SchumiDumitru Andrei Georgian Schumi Data 9 februarie 2012 15:58:48
Problema Trapez Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

const double eps = 1e-8;
int x[1005], y[1005], n, c, a, sol;
double p[1000005];

int egal(double a, double b)
{
    if(fabs(a - b) <= eps)
        return 1;
    return 0;
}

double panta(int a, int b)
{
    if(x[a] == x[b])
        return 0x3f3f3f3f;
    return (1.0 * (y[b] - y[a])) / (1.0 * (x[b] - x[a]));
}

int main()
{
    int i, j;
    freopen ("trapez.in", "r", stdin);
    freopen ("trapez.out", "w", stdout);
    scanf("%d", &n);
    for(i = 1; i <= n; ++i)
        scanf("%d %d", &x[i], &y[i]);
    for(i = 1; i < n; ++i)
        for(j = i; j <= n; ++j)
            p[++a] = panta(i, j);
    sort(p + 1, p + a + 1);
    for(i = 1; i < a; ++i) {
        if(egal(p[i], p[i + 1]))
            ++c;
        else {
            sol += c * (c + 1) / 2;
            c = 0;
        }
    }
    printf("%d", sol);
    return 0;
}