Cod sursa(job #1480660)

Utilizator eu3neuomManghiuc Teodor-Florin eu3neuom Data 2 septembrie 2015 23:09:21
Problema Patrate 3 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <iostream>
#include <fstream>
#include <unordered_set>

using namespace std;

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

#define H(x, y) (1LL * x * 1e9 + y)

const int NMax = 1005;

pair < int, int > Points[NMax];
unordered_set < long long int > Hash;

bool solve(int a, int b){
    int x = Points[a].first, y = Points[a].second,
        X = Points[b].first, Y = Points[b].second;
    int dx = X - x;
    int dy = y - Y;
    int z = x + dy, t = y + dx,
        Z = X + dy, T = Y + dx;
    return(Hash.find(H(z, t)) != Hash.end() && Hash.find(H(Z, T)) != Hash.end());
}

int main(){
    int n, ans;
    long double a, b;
    fin >> n;
    for(int i = 1; i <= n; i++){
        fin >> a >> b;
        a *= 1e4; b *= 1e4;
        Points[i] = make_pair(a, b);
        Hash.insert(H(a, b));
    }
    ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            ans += solve(i, j);
            ans += solve(j, i);
        }
    }
    fout << ans;
    return 0;
}