Cod sursa(job #2483852)

Utilizator AlexNeaguAlexandru AlexNeagu Data 30 octombrie 2019 13:57:37
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <bits/stdc++.h>
#define oo 2e9
#define x first
#define y second
using namespace std;
ifstream in("trapez.in");
ofstream out("trapez.out");
vector < long double > pante;
pair < int, int > a[1005];
long double afla_panta(pair < int, int > x, pair < int, int > y) {
  if (x.x == y.x) return oo;
  return (long double) (y.y - x.y) / (long double) (y.x - x.x);
}
int main() {
  int n, ans = 0;
  in >> n;
  for (int i = 1; i <= n; i++) {
    in >> a[i].x >> a[i].y;
  }
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      pante.push_back(afla_panta(a[i], a[j]));
    }
  }
  sort(pante.begin(), pante.end());
  int cnt = 1;
  for (int i = 1; i < pante.size(); i++) {
    if (pante[i] != pante[i - 1]) {
      ans += cnt * (cnt - 1) / 2;
      cnt = 1;
    }
    else {
      cnt++;
    }
  }
  ans += cnt * (cnt - 1) / 2;
  out << ans << "\n";
  return 0;
}