Cod sursa(job #1480666)

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

using namespace std;

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

#define var long long int
#define H(x, y) (x * 1e9 + y)

const int NMax = 1005;

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

bool solve(int a, int b){
    var x = Points[a].first, y = Points[a].second,
        X = Points[b].first, Y = Points[b].second;
    var dx = X - x, dy = y - Y;
    var 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());
}

char buff[15];
void Read(var &x){
    int pos = 0;
    bool s = 0;
    x = 0;
    fin >> buff;
    if(buff[pos] == '-'){
        s = 1;
        pos++;
    }
    for(; buff[pos]; pos++){
        if(isdigit(buff[pos])){
            x = x * 10 + buff[pos] - '0';
        }
    }
    if(s) x = -x;
}

int main(){
    var n, ans, a, b;
    fin >> n;
    for(int i = 1; i <= n; i++){
        Read(a); Read(b);
        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 / 4;
    return 0;
}