Cod sursa(job #1931460)

Utilizator 1475369147896537415369Andrei Udriste 1475369147896537415369 Data 19 martie 2017 13:37:36
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

#define undefined 2147483648

struct point{
    int x;
    int y;

    point(){x = 0; y = 0;}

    point(int _x, int _y){
        x = _x;
        y = _y;
    }
};

inline double slope(const point &p1, const point &p2){
    if(p2.x == p1.x) return undefined;
    return (double)(p2.y - p1.y) / (p2.x - p1.x);
}

point input[1002];
int N, s = 0, trapeze = 0, k = 1;
double slopes[499501], eps = 0.00000000001;

int main(){

    freopen("trapez.in", "r", stdin);
    freopen("trapez.out", "w", stdout);

    scanf("%d", &N);

    for(int i = 1; i <= N; i++){
        scanf("%d %d", &input[i].x, &input[i].y);
    }
    for(int i = 1; i <= N; i++){
        for(int j = i + 1; j <= N; j++){
            slopes[++s] = slope(input[i], input[j]);
        }
    }sort(slopes + 1, slopes + s + 1);

    for(int i = 1; i < s; i++){
        if(fabs(slopes[i] - slopes[i + 1]) <= eps) k++;
        else{
            trapeze += k*(k - 1) / 2;
            k = 1;
        }
    }printf("%d", trapeze);

    return 0;
}