summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2024-12-02 19:47:24 +0800
committerlittleblack111 <littleblack11111@gmail.com>2024-12-02 19:47:24 +0800
commitfbd3dab9f9c2a84b3f117462b29922d1e03984a6 (patch)
tree2a29685de8ae1b6ea52ef4ea20f38ff6b275d474
parent1375a6e2cb1cf91b0dd001904a72762b368de8f2 (diff)
add: 2.cpp
-rw-r--r--2024/2.in2
-rw-r--r--2024/2A.cpp1
-rwxr-xr-x2024/2Bbin0 -> 49712 bytes
-rw-r--r--2024/2B.cpp61
4 files changed, 63 insertions, 1 deletions
diff --git a/2024/2.in b/2024/2.in
index a837466..7761b29 100644
--- a/2024/2.in
+++ b/2024/2.in
@@ -997,4 +997,4 @@
23 26 29 32 34 35
18 17 15 13 12 10 7
51 48 45 42 40
-15 16 19 20 23 26 27
+15 16 19 20 23 26 27 \ No newline at end of file
diff --git a/2024/2A.cpp b/2024/2A.cpp
index 40ac6ca..be4594c 100644
--- a/2024/2A.cpp
+++ b/2024/2A.cpp
@@ -25,6 +25,7 @@ int main(int argc, char const *argv[])
increasing = true;
else if (prev > n)
decreasing = true;
+ // all conditions for unsafe lol
if (std::abs(prev - n) > 3 || prev == n || (n > prev && decreasing || n < prev && increasing || increasing && decreasing || !increasing && !decreasing)) {
safe = false;
break;
diff --git a/2024/2B b/2024/2B
new file mode 100755
index 0000000..56f15ea
--- /dev/null
+++ b/2024/2B
Binary files differ
diff --git a/2024/2B.cpp b/2024/2B.cpp
new file mode 100644
index 0000000..674f98f
--- /dev/null
+++ b/2024/2B.cpp
@@ -0,0 +1,61 @@
+#include <bits/stdc++.h>
+#include "readfile.hpp"
+
+int get_problem(const std::vector<int> &numbers) {
+ bool increasing = false, decreasing = false;
+ int prev = -1;
+ for (int i = 0; i < numbers.size(); ++i) {
+ if (prev == -1) {
+ prev = numbers[i];
+ continue;
+ }
+ if (prev < numbers[i])
+ increasing = true;
+ else if (prev > numbers[i])
+ decreasing = true;
+ if (std::abs(prev - numbers[i]) > 3 || prev == numbers[i] || increasing && decreasing || !increasing && !decreasing)
+ return i;
+ prev = numbers[i];
+ }
+ return -1;
+}
+
+
+int main(int argc, char const *argv[])
+{
+ int res = 0;
+ std::vector<std::string> file = readfile("2.in");
+ if (file.empty())
+ return 1;
+
+ for (const auto &line : file) {
+ std::istringstream iss(line);
+ std::vector<int> lv;
+ int n;
+ while (iss >> n) {
+ lv.push_back(n);
+ }
+ if (get_problem(lv) == -1) {
+ ++res;
+ continue;
+ }
+
+ // not safe / strike 1
+ // try removing the problem number
+ for (int i = 0; i < lv.size(); ++i) {
+ std::vector<int> lv2;
+ for (int j = 0; j < lv.size(); ++j) {
+ if (j == i)
+ continue;
+ lv2.push_back(lv[j]);
+ }
+ if (get_problem(lv2) == -1) {
+ ++res;
+ break;
+ }
+ }
+ }
+
+ // print
+ std::cout << res << std::endl;
+} \ No newline at end of file