Pagini recente » Cod sursa (job #250742) | Cod sursa (job #188552) | Cod sursa (job #1627806) | Cod sursa (job #1241770) | Cod sursa (job #2754456)
//
// main.cpp
// Patrate3
//
// Created by Mara Dascalu on 25/05/2021.
//IDEE PRELUATA DIN PRIMUL RASPUNS : //https://math.stackexchange.com/questions/958381/how-to-find-the-number-of-squares-formed-by-given-lattice-points
#include <iostream>
#include <fstream>
#include <set>
#include <math.h>
using namespace std;
ifstream input("patrate3.in");
ofstream output("patrate3.out");
const int n_max = 1000;
set<pair<int, int>> coordonate;
pair<int, int> a[n_max+1];
int n, patrat;
double x,y;
void verifPatrat (pair<int, int> x, pair<int, int> y)
{
int dif_x, dif_y;
dif_x = x.first - y.first;
dif_y = y.second - x.second;
if (coordonate.find({x.first + dif_y , x.second + dif_x}) != coordonate.end() && coordonate.find({y.first + dif_y, y.second + dif_x}) != coordonate.end())
patrat++;
}
int main(int argc, const char * argv[]) {
input>>n;
for (int i = 1; i <= n; i++)
{
input>>x>>y;
a[i].first = round(x * 10000);
a[i].second = round(y * 10000);
coordonate.insert(a[i]);
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (i != j)
{
verifPatrat(a[i], a[j]);
}
output<<patrat/4;
}