Cod sursa(job #2872787)

Utilizator TeodorLuchianovTeo Luchianov TeodorLuchianov Data 17 martie 2022 20:23:19
Problema Patrate 3 Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.54 kb
#include <fstream>
#include <cmath>
#include <set>

using namespace std;

ifstream in("patrate3.in");
ofstream out("patrate3.out");

int const NMAX = 1000;
pair <int, int> point[1 + NMAX];

set <pair <int, int> > isPoint;

bool isUpperSquare(pair <int, int> a, pair <int, int> b) {
  if(a.second == b.second) {
    int lat = abs(a.first - b.first);
    auto c = isPoint.find({a.first, a.second + lat});
    auto d = isPoint.find({b.first, b.second + lat});
    if(c != isPoint.end() && d != isPoint.end()){
      return true;
    }

  }else {
    int flat = (b.first - a.first), slat = abs(b.second - a.second);
    auto c = isPoint.find({a.first + slat, a.second + flat});
    auto d = isPoint.find({b.first + slat, b.second + flat});
    if(c != isPoint.end() && d != isPoint.end()){
      return true;
    }
  }
  return false;
}

int readNumber() {
  int ans = 0;
  char ch;
  while(in >> ch && ch != '.'){
    ans = ans * 10 + ch - '0';
  }
  for(int i = 0;i < 4;i++){
    in >> ch;
    ans = ans * 10 + ch - '0';
  }
  return ans;
}

int main() {

  int n;
  in >> n;
  for(int i = 1;i <= n;i++) {
    point[i].first = readNumber();
    point[i].second = readNumber();
    isPoint.insert(point[i]);
  }
  int ans = 0;
  for(int i = 1;i <= n;i++) {
    for(int j = 1;j <= n;j++){
      if(point[i].first < point[j].first && (point[j].second - point[i].second) / (point[j].first - point[i].first) <= 0 && isUpperSquare(point[i], point[j])){
        ans++;
      }
    }
  }
  out << ans;
  return 0;
}