Cod sursa(job #2011462)

Utilizator stefan_creastaStefan Creasta stefan_creasta Data 16 august 2017 12:54:44
Problema Trapez Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <cstdio>
#include <algorithm>
using namespace std;
const int NMAX = 1005;
const int INF = 0x3f3f3f3f;
struct ABC
{
    int x, y;
};
double a[NMAX];
ABC v[NMAX];

int main()
{
    long long sum = 0;
    int n, i, j, top = 0, nr;
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    scanf("%d", &n);
    for(i = 1;i <= n; ++i) {
        scanf("%d%d", &v[i].x, &v[i].y);
    }
    for(i = 1;i <= n; ++i) {
        for(j = i + 1;j <= n; ++j) {
            if(v[i].x == v[j].x) {
                a[++top] = (double)INF;
            }
            else {
                a[++top] = (double)(v[j].y - v[i].y) / (v[j].x - v[i].x);
            }
        }
    }
    sort(a + 1, a + top + 1);
    nr = 1;
    for(i = 2;i <= top; ++i) {
        if(a[i] == a[i - 1]) {
            ++nr;
        }
        else {
            sum += (nr * (nr - 1));
            nr = 1;
        }
    }
    printf("%lld", sum / 2);
    return 0;
}