Pagini recente » Cod sursa (job #1532855) | Cod sursa (job #951957) | Cod sursa (job #2458581) | Cod sursa (job #1552464) | Cod sursa (job #2755540)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("patrate3.in");
ofstream fout("patrate3.out");
set<pair<int,int>> h; //set, ca sa nu se repete punctele, la unordered map s-ar fi putur repeta abscisa
pair<int,int> v[1001];
bool patrat(pair<int,int> a, pair<int,int> b)
{
int x, y;
//verificam daca sunt egale coordonatele celorlalte 2 puncte
x = a.second - b.second;
y = b.first - a.first;
pair<int,int> aux1,aux2;
aux1.first = a.first + x;
aux1.second = a.second + y;
aux2.first = b.first + x;
aux2.second = b.second + y;
if(h.find(aux1) != h.end() && h.find(aux2) != h.end())
return 1;
return 0;
}
int main()
{
int n, c = 0;
double x,y;
fin>>n;
for(int i = 1; i <= n; i++)
{
fin>>x>>y;
v[i].first = round(x * 10000);
v[i].second = round(y * 10000);
h.insert(v[i]);
}
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
if(i != j && patrat(v[i],v[j]))
c++;
fout<<c/4; //patratul este numarat pt fiecare varf al sau, deci impartim la 4
return 0;
}