Cod sursa(job #1991177)

Utilizator DjokValeriu Motroi Djok Data 15 iunie 2017 15:02:46
Problema Patrate 3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.42 kb
#include <bits/stdc++.h>
using namespace std;

const double PI = acos(-1);
const double EPS = 1e-12;
const int N = 1005;

struct point {
  double x, y;

  point(double x = 0, double y = 0) {
    this->x = x;
    this->y = y;
  }

  double dist(point b) {
    double dx = x - b.x;
    double dy = y - b.y;
    return sqrt(dx * dx + dy * dy);
  }

  void rot(double alfa) {
    alfa = alfa * PI / 180.0;

    double xx = x * cos(alfa) - y * sin(alfa);
    double yy = x * sin(alfa) + y * cos(alfa);

    x = xx; y = yy;
  }

  point translate(point b) {
    point ans(x - b.x, y - b.y);
    return ans;
  } 

  bool operator < (const point &p) const {
    return x < p.x - EPS || abs(x - p.x) < EPS && y < p.y - EPS;
  }
};


int i, j, n, rs;
set<point> S;
point a[N];

bool check(point A, point B) {
  point M((A.x + B.x) * 0.5, (A.y + B.y) * 0.5);

  A = A.translate(M);
  B = B.translate(M);

  A.rot(90); B.rot(90);

  M.x = -M.x; M.y = -M.y;
  A = A.translate(M);
  B = B.translate(M);

  return S.count(A) && S.count(B);
}

int main() {
  ifstream cin("patrate3.in");
  ofstream cout("patrate3.out");
  ios_base::sync_with_stdio(0);

  cin >> n;
  for(i = 1; i <= n; ++i) cin >> a[i].x >> a[i].y, S.insert(a[i]);

  sort(a + 1, a + n + 1);

  for(i = 1; i <= n; ++i)
    for(j = i + 1; j <= n; ++j)
      if(check(a[i], a[j])) ++rs;

  cout << rs / 2 << '\n';

  return 0;
}