Cod sursa(job #2872789)

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

using namespace std;

typedef long long ll;

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

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

set <pair <ll, ll> > isPoint;

bool isUpperSquare(pair <ll, ll> a, pair <ll, ll> b) {
  if(a.second == b.second) {
    ll 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 {
    ll 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;
}

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

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) <= 0 && isUpperSquare(point[i], point[j])){
        ans++;
      }
    }
  }
  out << ans;
  return 0;
}