Cod sursa(job #2607685)

Utilizator Stefan_RaduStefan Radu Stefan_Radu Data 30 aprilie 2020 00:47:32
Problema Trapez Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.23 kb
// By Stefan Radu

#include <algorithm>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <string>
#include <cctype>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <map>
#include <set>

using namespace std;

ifstream cin("trapez.in");
ofstream cout("trapez.out");

#define sz(x) (int)(x).size()

typedef pair < int, int > pii;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

struct Point {
  int x, y;
};

double slope(const Point &a, const Point &b) {
  return static_cast < double >(a.y - b.y) / static_cast<double>(a.x - b.x); 
}

int main() {

#ifdef STEF
  freopen("input", "r", stdin);
  freopen("output", "w", stdout);
#endif

  ios::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);

  int n; cin >> n;
  vector < Point > points(n);

  for (auto &p : points) {
    cin >> p.x >> p.y;
  }

  map < double, int > cnt;

  for (int i = 0; i < n; ++ i) {
    for (int j = i + 1; j < n; ++ j) {
      cnt[slope(points[i], points[j])] += 1;
    }
  }

  int ans = 0;
  for (const auto &x : cnt) {
    ans += x.second * (x.second - 1) / 2;
  }

  cout << ans << '\n';
}