diff --git a/2024/8/main-1.cpp b/2024/8/main-1.cpp new file mode 100644 index 0000000..4c97a43 --- /dev/null +++ b/2024/8/main-1.cpp @@ -0,0 +1,46 @@ +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + map>> nodes; + string line; + vector lines; + while (getline(cin, line) && !line.empty()) { + lines.push_back(line); + } + + int mx = lines.size(), my = lines[0].size(); + + for (int x = 0; x < mx; x++) { + for (int y = 0; y < my; y++) { + char c = lines[x][y]; + if (c != '.') { + nodes[c].push_back({x, y}); + } + } + } + + set> total; + for (auto &[c, poss] : nodes) { + for (int a = 1; a < poss.size(); a++) { + for (int b = 0; b < a; b++) { + vector> pos = { + {poss[b].first * 2 - poss[a].first, + poss[b].second * 2 - poss[a].second}, + {poss[a].first * 2 - poss[b].first, + poss[a].second * 2 - poss[b].second}}; + for (auto &x : pos) { + if (x.first >= 0 && x.first < mx && x.second >= 0 && + x.second < my) { + total.insert(x); + } + } + } + } + } + + cout << total.size() << '\n'; +} diff --git a/2024/8/main-2.cpp b/2024/8/main-2.cpp new file mode 100644 index 0000000..28fd1b5 --- /dev/null +++ b/2024/8/main-2.cpp @@ -0,0 +1,50 @@ +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + map>> nodes; + string line; + vector lines; + while (getline(cin, line) && !line.empty()) { + lines.push_back(line); + } + + int mx = lines.size(), my = lines[0].size(); + + for (int x = 0; x < mx; x++) { + for (int y = 0; y < my; y++) { + char c = lines[x][y]; + if (c != '.') { + nodes[c].push_back({x, y}); + } + } + } + + set> total; + for (auto &[c, poss] : nodes) { + for (int a = 1; a < poss.size(); a++) { + for (int b = 0; b < a; b++) { + int dx = poss[a].first - poss[b].first; + int dy = poss[a].second - poss[b].second; + int x = poss[a].first, y = poss[a].second; + while (x >= 0 && x < mx && y >= 0 && y < my) { + x -= dx; + y -= dy; + } + for (;;) { + x += dx; + y += dy; + if (!(x >= 0 && x < mx && y >= 0 && y < my)) { + break; + } + total.insert({x, y}); + } + } + } + } + + cout << total.size() << '\n'; +}