Pagini recente » Cod sursa (job #918866) | Cod sursa (job #1644923) | Cod sursa (job #2340429) | Cod sursa (job #1830012) | Cod sursa (job #2624997)
#include <algorithm>
#include <cstddef>
#include <fstream>
#include <iterator>
#include <utility>
#include <vector>
using coord_t = std::pair<int, int>;
constexpr int digits = 10'000;
auto to_int(double const num) -> int
{
return static_cast<int>(num * digits);
}
auto operator/(coord_t const& a, int const b) -> coord_t
{
return { a.first / b, a.second / b };
}
auto operator+(coord_t const& a, coord_t const& b) -> coord_t
{
return { a.first + b.first, a.second + b.second };
}
auto main() noexcept -> int
{
std::ifstream f{ "patrate3.in" };
std::ofstream g{ "patrate3.out" };
std::vector<coord_t> points{};
std::size_t n{ 0 };
std::size_t count{ 0 };
f >> n;
points.reserve(n);
for(std::size_t i = 0; i < n; ++i) {
double x{ 0 };
double y{ 0 };
f >> x >> y;
points.emplace_back(to_int(x), to_int(y));
}
std::sort(points.begin(), points.end());
for(std::size_t i = 0; i < n - 1; ++i) {
for(std::size_t j = i + 1; j < n; ++j) {
auto const mid = (points[i] + points[j]) / 2;
coord_t const distance{ mid.first - points[i].first,
mid.second - points[i].second };
coord_t const point1{ mid.first + distance.second,
mid.second - distance.first };
coord_t const point2{ mid.first - distance.second,
mid.second + distance.first };
auto from = points.begin();
std::advance(from, i + 1);
auto to = points.end();
if(std::binary_search(from, to, point1) &&
std::binary_search(from, to, point2)) {
++count;
}
}
}
g << count << std::endl;
}