Cod sursa(job #2973589)

Utilizator smunteanuMunteanu Stefan Catalin smunteanu Data 1 februarie 2023 13:00:00
Problema Trapez Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <bits/stdc++.h>
using namespace std;

void solve() {
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  vector<double> lines;
  lines.reserve(n * n);
  for (auto& [x, y] : a) cin >> x >> y;
  for (int i = 0; i < n; i++) {
    const auto& [x1, y1] = a[i];
    for (int j = i + 1; j < n; j++) {
      const auto& [x2, y2] = a[j];
      lines.push_back((double)(x1 - x2) / (double)(y1 - y2));
    }
  }
  sort(lines.begin(), lines.end());
  int t = n * (n - 1), r = 0;
  for (int i = 0, j = 0; i < n; i = j) {
    while (j < n && lines[i] == lines[j]) j++;
    r += (j - i) * (j - i - 1) / 2;
  }
  cout << r << '\n';
}

int main() {

  #ifdef LOCAL
  freopen("file.in", "r", stdin);
  #else
  freopen("trapez.in", "r", stdin);
  freopen("trapez.out", "w", stdout);
  #endif

  ios_base::sync_with_stdio(false), cin.tie(NULL);

  solve();
}