Cod sursa(job #1703497)

Utilizator oldatlantianSerban Cercelescu oldatlantian Data 17 mai 2016 00:10:08
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <bits/stdc++.h>
using namespace std;

const double INF=2e9+5;
const double eps=1.e-14;


struct POINT {
    double x, y;
};
vector <double> pan;
POINT a[1010];

inline bool vertical(POINT A, POINT B) {
    return A.x==B.x;
}
inline void panta(POINT A, POINT B) {
    if(vertical(A, B)) {
        pan.push_back(INF);
        return;
    }
    pan.push_back((B.y-A.y)/(B.x-A.x));
}
int main(void) {
    freopen("trapez.in", "r", stdin);
    freopen("trapez.out", "w", stdout);

    int n, i, j, sum=0, nr=0;
    double last, x, y;

    scanf("%d", &n);
    for(i=1; i<=n; i++) {
        scanf("%lf%lf", &x, &y);
        a[i].x = x;
        a[i].y = y;
    }
    for(i=1; i<n; i++)
        for(j=i+1; j<=n; j++)
            panta(a[i], a[j]);
    sort(pan.begin(), pan.end());
    last = pan[0];
    nr = 1;

    for(i=1; i<pan.size() ;i++) {
        if(last==pan[i])
            nr++;
        else {
            if(nr>1)
                sum+=(nr*(nr-1)/2);
            nr=1;
            last=pan[i];
        }
    }
    printf("%d\n", sum);
    return 0;
}