2024 day 13

This commit is contained in:
eriedaberrie 2024-12-12 22:38:22 -08:00
parent 0ad4f00d6d
commit d82693c074
2 changed files with 88 additions and 0 deletions

45
2024/13/main-1.cpp Normal file
View file

@ -0,0 +1,45 @@
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int total = 0;
while (!cin.eof()) {
int ax, ay, bx, by, px, py;
cin.ignore(12);
cin >> ax;
cin.ignore(4);
cin >> ay;
cin.ignore(13);
cin >> bx;
cin.ignore(4);
cin >> by;
cin.ignore(10);
cin >> px;
cin.ignore(4);
cin >> py;
cin.ignore(2);
int smallest = -1;
for (int a = 0; a <= 100; a++) {
for (int b = 0; b <= 100; b++) {
if (ax * a + bx * b == px && ay * a + by * b == py) {
int n = a * 3 + b;
if (smallest == -1 || n < smallest) {
smallest = n;
}
}
}
}
if (smallest != -1) {
total += smallest;
}
}
cout << total << '\n';
}

43
2024/13/main-2.cpp Normal file
View file

@ -0,0 +1,43 @@
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll total = 0;
while (!cin.eof()) {
int ax, ay, bx, by;
ll px, py;
cin.ignore(12);
cin >> ax;
cin.ignore(4);
cin >> ay;
cin.ignore(13);
cin >> bx;
cin.ignore(4);
cin >> by;
cin.ignore(10);
cin >> px;
cin.ignore(4);
cin >> py;
cin.ignore(2);
px += 10000000000000;
py += 10000000000000;
ll bd = bx * ay - by * ax;
ll pd = px * ay - py * ax;
if (pd % bd != 0) {
continue;
}
ll b = pd / bd;
ll a = (px - bx * b) / ax;
total += a * 3 + b;
}
cout << total << '\n';
}