diff --git a/2024/14/main-1.cpp b/2024/14/main-1.cpp new file mode 100644 index 0000000..88ff04a --- /dev/null +++ b/2024/14/main-1.cpp @@ -0,0 +1,58 @@ +#include +using namespace std; + +const int mx = 101; +const int my = 103; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + vector, pair>> robots; + string line; + while (getline(cin, line) && !line.empty()) { + istringstream l(line); + l.ignore(2); + int px, py, vx, vy; + l >> px; + l.ignore(1); + l >> py; + l.ignore(3); + l >> vx; + l.ignore(1); + l >> vy; + if (vx < 0) { + vx += mx; + } + if (vy < 0) { + vy += my; + } + robots.push_back({{px, py}, {vx, vy}}); + } + + int q1 = 0, q2 = 0, q3 = 0, q4 = 0; + for (auto &[p, v] : robots) { + auto &[px, py] = p; + auto &[vx, vy] = v; + for (int i = 0; i < 100; i++) { + px = (px + vx) % mx; + py = (py + vy) % my; + } + + if (px < mx / 2) { + if (py < my / 2) { + q1 += 1; + } else if (py > my / 2) { + q2 += 1; + } + } else if (px > mx / 2) { + if (py < my / 2) { + q3 += 1; + } else if (py > my / 2) { + q4 += 1; + } + } + } + + cout << q1 * q2 * q3 * q4 << '\n'; +} diff --git a/2024/14/main-2.cpp b/2024/14/main-2.cpp new file mode 100644 index 0000000..f7dca93 --- /dev/null +++ b/2024/14/main-2.cpp @@ -0,0 +1,73 @@ +#include +using namespace std; + +const int mx = 101; +const int my = 103; + +int main(int argc, char *argv[]) { + ios::sync_with_stdio(0); + + ifstream fin(argc > 0 ? argv[1] : "data.txt"); + // NOTE: 14 and 101 for my dataset + int start = argc >= 3 ? atoi(argv[2]) : 0; + int step = argc >= 3 ? atoi(argv[3]) : 1; + + vector, pair>> robots; + string line; + while (getline(fin, line) && !line.empty()) { + istringstream l(line); + l.ignore(2); + int px, py, vx, vy; + l >> px; + l.ignore(1); + l >> py; + l.ignore(3); + l >> vx; + l.ignore(1); + l >> vy; + if (vx < 0) { + vx += mx; + } + if (vy < 0) { + vy += my; + } + robots.push_back({{px, py}, {vx, vy}}); + } + + char m[my][mx]; + + int n = start; + for (auto &[p, v] : robots) { + auto &[px, py] = p; + auto &[vx, vy] = v; + for (int i = 0; i < start; i++) { + px = (px + vx) % mx; + py = (py + vy) % my; + } + } + + for (;;) { + memset(m, ' ', mx * my); + + for (auto &[p, v] : robots) { + auto &[px, py] = p; + auto &[vx, vy] = v; + m[py][px] = '*'; + for (int i = 0; i < step; i++) { + px = (px + vx) % mx; + py = (py + vy) % my; + } + } + + for (int y = 0; y < my; y++) { + for (int x = 0; x < mx; x++) { + cout << m[y][x]; + } + cout << '\n'; + } + cout << n << '\n'; + n += step; + + cin.ignore(); + } +}