Cod sursa(job #2221307)

Utilizator mateicosCostescu Matei mateicos Data 13 iulie 2018 17:57:43
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

const double INF = 1e9;
const double eps = 1e-14;

class POINT{
private:
    double x, y;
public:
    POINT(){
      x = 0;
      y = 0;
    }
    void SetPoint(int x1, int x2){
      x = x1;
      y = x2;
    }
    double panta(const POINT &other){
      if(fabs(1.0 * x - other.x) < eps)
        return INF;
        return (1.0 * y - other.y) / (1.0*x - other.x);
    }
}a[1005];

double v[1000005];

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