Pagini recente » Cod sursa (job #53880) | Cod sursa (job #677759) | Cod sursa (job #2447538) | Cod sursa (job #1193749) | Cod sursa (job #2746820)
#include <fstream>
std::ifstream fin("patrate3.in");
std::ofstream fout("patrate3.out");
#include <vector>
#include <unordered_map>
#include <string>
using i64 = std::int32_t;
int mstoi(const std::string& str)
{
static constexpr int pow10[] = {1, 10, 100, 1000, 10000,
100000, 1000000, 10000000, 100000000, 1000000000};
auto it = str.rbegin();
int res =
(it[0] - '0') + (it[1] - '0') * 10 + (it[2] - '0') * 100 + (it[3] - '0') * 1000;
it += 5;
unsigned i = 4;
while(it != str.rend() - 1)
{
res += (*it - '0') * pow10[i++];
++it;
}
if(str.front() == '-')
{
return -1 * res;
}
else
{
return res + (str.front() - '0') * pow10[i];
}
}
struct Point
{
static i64 dist(const Point& p1, const Point& p2)
{
const i64 d1 = p1.x - p2.x;
const i64 d2 = p1.y - p2.y;
const i64 dist = d1 * d1 + d2 * d2;
return dist;
}
i64 x, y;
};
struct Segment
{
Point p1, p2;
};
bool same_dist(const Point& p, const Point& p1, const Point& p2)
{
return Point::dist(p, p1) == Point::dist(p, p2);
}
bool form_square(const Segment& s1, const Segment& s2)
{
return same_dist(s1.p1, s2.p1, s2.p2) && same_dist(s1.p2, s2.p1, s2.p2) &&
same_dist(s2.p1, s1.p1, s1.p2) && same_dist(s2.p2, s1.p1, s1.p1);
}
int main()
{
unsigned N;
fin >> N;
std::vector<Point> points;
{
std::string x, y;
x.reserve(10);
y.reserve(10);
for(unsigned i = 0; i < N; ++i)
{
std::string x;
std::string y;
fin >> x >> y;
points.push_back({mstoi(x), mstoi(y)});
}
}
for(auto p : points)
{
fout << p.x << ' ' << p.y << '\n';
}
return 0;
std::unordered_map<int, std::vector<Segment>> table;
for(unsigned i = 0; i < N - 1; ++i)
{
for(unsigned j = i + 1; j < N; ++j)
{
// fmt::print(stderr, "err\n");
const i64 dist = Point::dist(points[i], points[j]);
table[dist].push_back({points[i], points[j]});
}
}
// points.~vector();
unsigned res = 0;
for(const auto& dist_bucket : table)
{
const auto& current_segments = dist_bucket.second;
if(current_segments.size() < 2)
{
continue;
}
for(unsigned i = 0; i < current_segments.size() - 1; ++i)
{
for(unsigned j = i + 1; j < current_segments.size(); ++j)
{
res += form_square(current_segments[i], current_segments[j]);
}
}
}
fout << res << '\n';
}