2023 day 5
I did not have fun These problems were very unenjoyable imo (skill issue probably)
This commit is contained in:
parent
190b9c6ff9
commit
a814a54c34
39
2023/5/main-1.cpp
Normal file
39
2023/5/main-1.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
|
||||
cin.ignore(6);
|
||||
string line;
|
||||
getline(cin, line);
|
||||
istringstream sls(line);
|
||||
vector<long> seeds;
|
||||
vector<bool> done;
|
||||
while (!sls.eof()) {
|
||||
long n;
|
||||
sls >> n;
|
||||
seeds.push_back(n);
|
||||
done.push_back(false);
|
||||
}
|
||||
cin.ignore(1);
|
||||
|
||||
for (int mapn = 0; mapn < 7; mapn++) {
|
||||
cin.ignore(500, '\n');
|
||||
while (getline(cin, line) && !line.empty()) {
|
||||
istringstream sls(line);
|
||||
long d, s, r;
|
||||
sls >> d >> s >> r;
|
||||
for (int i = 0; i < seeds.size(); i++) {
|
||||
if (!done[i] && seeds[i] >= s && seeds[i] < s + r) {
|
||||
seeds[i] += d - s;
|
||||
done[i] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
fill(done.begin(), done.end(), false);
|
||||
}
|
||||
|
||||
cout << *min_element(seeds.begin(), seeds.end()) << '\n';
|
||||
}
|
66
2023/5/main-2.cpp
Normal file
66
2023/5/main-2.cpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
|
||||
cin.ignore(6);
|
||||
string line;
|
||||
getline(cin, line);
|
||||
istringstream sls(line);
|
||||
vector<pair<long, long>> seeds;
|
||||
vector<bool> done;
|
||||
while (!sls.eof()) {
|
||||
long n, nn;
|
||||
sls >> n >> nn;
|
||||
seeds.push_back(make_pair(n, n + nn - 1));
|
||||
done.push_back(false);
|
||||
}
|
||||
cin.ignore(1);
|
||||
|
||||
for (int mapn = 0; mapn < 7; mapn++) {
|
||||
cin.ignore(500, '\n');
|
||||
while (getline(cin, line) && !line.empty()) {
|
||||
istringstream sls(line);
|
||||
long d, s, r;
|
||||
sls >> d >> s >> r;
|
||||
int ssize = seeds.size();
|
||||
for (int i = 0; i < ssize; i++) {
|
||||
if (done[i])
|
||||
continue;
|
||||
auto& curr = seeds[i];
|
||||
long *curs = &get<0>(curr), *cure = &get<1>(curr);
|
||||
if (*curs >= s) {
|
||||
if (*cure < s + r) {
|
||||
*curs += d - s;
|
||||
*cure += d - s;
|
||||
done[i] = true;
|
||||
} else if (*curs < s + r) {
|
||||
seeds.push_back(make_pair(*curs + d - s, d + r - 1));
|
||||
done.push_back(true);
|
||||
*curs = s + r;
|
||||
}
|
||||
} else if (*cure > s + r) {
|
||||
seeds.push_back(make_pair(d, d + r - 1));
|
||||
done.push_back(true);
|
||||
seeds.push_back(make_pair(s + r, *cure));
|
||||
done.push_back(false);
|
||||
*cure = s - 1;
|
||||
} else if (*cure > s) {
|
||||
seeds.push_back(make_pair(d, *cure + d - s));
|
||||
done.push_back(true);
|
||||
*cure = s - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
fill(done.begin(), done.end(), false);
|
||||
}
|
||||
|
||||
int min = INT_MAX;
|
||||
for (auto& r : seeds) {
|
||||
if (get<0>(r) < min)
|
||||
min = get<0>(r);
|
||||
}
|
||||
cout << min << '\n';
|
||||
}
|
Loading…
Reference in a new issue