Pagini recente » Cod sursa (job #2426811) | Cod sursa (job #2110075) | Cod sursa (job #413335) | Cod sursa (job #807086) | Cod sursa (job #2745710)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("patrate3.in");
ofstream fout("patrate3.out");
unordered_map<int, int> h; /// un hash ce contine elemente de forma abscisa : ordonata
int n, ct;
pair<int, int> a[1005];
void citire(){
double x,y;
fin>>n;
for(int i = 1; i <= n; ++ i){
fin>>x>>y;
a[i].first = round(x * 10000);
a[i].second = round(y * 10000);
h[a[i].first] = a[i].second;
}
}
int verify(pair<int,int> a, pair<int,int> b)
{
/// calculam coordonatele celorlalte 2 puncte si verificam daca sunt egale
int x, y;
if(a==b){
return 0;
}
y = b.first - a.first;
x = a.second - b.second;
return (h[a.first+x] == a.second+y && h[b.first+x] == b.second+y);
}
int main()
{
citire();
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= n; j ++)
if(verify(a[i],a[j]))
ct++;
fout<<ct/4; /// fiecare patrat este numarat de 4 ori
return 0;
}