Pagini recente » Cod sursa (job #1116211) | Cod sursa (job #161426) | Cod sursa (job #2308605) | Cod sursa (job #2579850) | Cod sursa (job #2749071)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("patrate3.in");
ofstream fout("patrate3.out");
set<pair <int, int>> h; ///coordonatele punctelor --> va fi f usor de gasit un punct O(1)
pair<int, int> a[1005];
int n, sol;
void read()
{
double x, y;
int i;
fin >> n;
for(i = 1; i <= n; ++i)
{
fin >> x >> y;
a[i].first = round(x * 10000); ///pt convertire
a[i].second = round(y * 10000);
h.insert(a[i]);
}
}
//va fi apelata de multe ori
inline bool square(pair <int, int> a, pair<int, int> b)
{
int x, y;
y = b.first - a.first;
x = a.second - b. second;
if(h.find({a.first + x, a.second + y}) != h.end() && h.find({b.first + x, b.second + y}) != h.end())///caut latura paralela aferenta
return 1;
return 0;
}
int main()
{
read();
int i, j;
for(i = 1; i <= n; ++i)
for(j = 1; j <= n; ++j)
if(i != j && square(a[i], a[j]))
sol++;
fout << sol/4;
///va fi numarat de 4 ori pt ca face pt fiecare latura
return 0;
}