Pagini recente » Cod sursa (job #749236) | Cod sursa (job #922836) | Cod sursa (job #2812322) | Cod sursa (job #2701166) | Cod sursa (job #2755983)
//https://math.stackexchange.com/questions/958381/how-to-find-the-number-of-squares-formed-by-given-lattice-points
#include <iostream>
#include <vector>
#include <fstream>
#include <set>
#include <cmath>
#define N 1001
using namespace std;
ifstream fin("patrate3.in");
ofstream fout("patrate.out");
pair<int, int> v[N];
set<pair<int, int> > p;
int n;
int ct;
void Citire()
{
int i;
float x, y;
fin >> n;
for (i = 0; i < n; i++)
{
fin >> x >> y;
v[i].first = round(x * (N - 1));
v[i].second = round(y * (N - 1));
p.insert(v[i]);
}
}
void Vf(pair<int, int> p1, pair<int, int> p2)
{
pair<int, int> p3;
pair<int, int> p4;
p3.first = p1.first + (p2.second - p1.second);
p3.second = p1.second + (p1.first - p2.first);
p4.first = p2.first + (p2.second - p1.second);
p4.second = p2.second + (p1.first - p2.first);
if (p.find({ p3.first, p3.second }) != p.end() && p.find({ p4.first, p4.second }) != p.end())
{
//cout << p3.first <<" "<<p3.second<<" "<<p4.first<<" "<<p4.second << "\n";
ct++;
}
}
void Solve()
{
int i, j;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
if (i != j)
Vf(v[i], v[j]);
}
int main()
{
Citire();
Solve();
fout << ct / 4;
return 0;
}