From 8bc4dddb0874e6095d8c2ce0e0c0b7cb702e1786 Mon Sep 17 00:00:00 2001 From: Segcolt <9hmbzr275@mozmail.com> Date: Thu, 14 Nov 2024 15:15:51 -0300 Subject: [PATCH] Add a bunch of easy problems I was waiting for my friend, that's it. --- CSES Problem Set/Increasing Array.cpp | 91 +++++++++++++++++++++++ CSES Problem Set/Missing Number.cpp | 90 ++++++++++++++++++++++ CSES Problem Set/Permutations.cpp | 103 ++++++++++++++++++++++++++ CSES Problem Set/Repetitions.cpp | 93 +++++++++++++++++++++++ CSES Problem Set/Weird Algorithm.cpp | 90 ++++++++++++++++++++++ 5 files changed, 467 insertions(+) create mode 100644 CSES Problem Set/Increasing Array.cpp create mode 100644 CSES Problem Set/Missing Number.cpp create mode 100644 CSES Problem Set/Permutations.cpp create mode 100644 CSES Problem Set/Repetitions.cpp create mode 100644 CSES Problem Set/Weird Algorithm.cpp diff --git a/CSES Problem Set/Increasing Array.cpp b/CSES Problem Set/Increasing Array.cpp new file mode 100644 index 0000000..f435ee1 --- /dev/null +++ b/CSES Problem Set/Increasing Array.cpp @@ -0,0 +1,91 @@ +/* Problem URL: https://cses.fi/problemset/task/1094 */ + +#include + +using namespace std; + +#define V vector + +#define rmin(a, b) a = min(a, b) +#define rmax(a, b) a = max(a, b) + +#define rep(i, lim) for (size_t i = 0; i < (lim); i++) +#define nrep(i, s, lim) for (size_t i = s; i < (lim); i++) + +#define repv(i, v) for (auto &i : (v)) +#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; } +#define sortv(v) sort(v.begin(), v.end()) +#define all(v) (v).begin(), (v).end() + +using vi = vector; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &vec)->ostream& { + for (auto &i : vec) { + os << i[0]; + for (size_t j = 1; j < i.size(); j++) { + os << ' ' << i[j]; + } + os << '\n'; + } + return os; +} + +template +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + int n; + cin >> n; + vl nums(n); + cin >> nums; + + ll ans = 0; + nrep(i, 1, n) { + if (nums[i] < nums[i - 1]) { + ans += nums[i - 1] - nums[i]; + nums[i] = nums[i - 1]; + } + } + + cout << ans << '\n'; +} diff --git a/CSES Problem Set/Missing Number.cpp b/CSES Problem Set/Missing Number.cpp new file mode 100644 index 0000000..4828400 --- /dev/null +++ b/CSES Problem Set/Missing Number.cpp @@ -0,0 +1,90 @@ +/* Problem URL: https://cses.fi/problemset/task/1083 */ + +#include + +using namespace std; + +#define V vector + +#define rmin(a, b) a = min(a, b) +#define rmax(a, b) a = max(a, b) + +#define rep(i, lim) for (size_t i = 0; i < (lim); i++) +#define nrep(i, s, lim) for (size_t i = s; i < (lim); i++) + +#define repv(i, v) for (auto &i : (v)) +#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; } +#define sortv(v) sort(v.begin(), v.end()) +#define all(v) (v).begin(), (v).end() + +using vi = vector; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &vec)->ostream& { + for (auto &i : vec) { + os << i[0]; + for (size_t j = 1; j < i.size(); j++) { + os << ' ' << i[j]; + } + os << '\n'; + } + return os; +} + +template +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + int n; + cin >> n; + vi nums(n - 1); + cin >> nums; + sortv(nums); + nums.push_back(INT32_MAX); + + rep(i, n) { + if (i + 1 != nums[i]) { + cout << i + 1 << '\n'; + return 0; + } + } +} diff --git a/CSES Problem Set/Permutations.cpp b/CSES Problem Set/Permutations.cpp new file mode 100644 index 0000000..16c0f31 --- /dev/null +++ b/CSES Problem Set/Permutations.cpp @@ -0,0 +1,103 @@ +/* Problem URL: https://cses.fi/problemset/task/1070 */ + +#include + +using namespace std; + +#define V vector + +#define rmin(a, b) a = min(a, b) +#define rmax(a, b) a = max(a, b) + +#define rep(i, lim) for (size_t i = 0; i < (lim); i++) +#define nrep(i, s, lim) for (size_t i = s; i < (lim); i++) + +#define repv(i, v) for (auto &i : (v)) +#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; } +#define sortv(v) sort(v.begin(), v.end()) +#define all(v) (v).begin(), (v).end() + +using vi = vector; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &vec)->ostream& { + for (auto &i : vec) { + os << i[0]; + for (size_t j = 1; j < i.size(); j++) { + os << ' ' << i[j]; + } + os << '\n'; + } + return os; +} + +template +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + int n; + cin >> n; + + if (n == 1) { + cout << "1\n"; + return 0; + } + + if (n <= 3) { + cout << "NO SOLUTION\n"; + return 0; + } + + if (n == 4) { + cout << "2 4 1 3\n"; + return 0; + } + + for (size_t i = 1; i <= n; i += 2) { + cout << i << ' '; + } + + for (size_t i = 2; i <= n; i += 2) { + cout << i << ' '; + } + cout << '\n'; +} diff --git a/CSES Problem Set/Repetitions.cpp b/CSES Problem Set/Repetitions.cpp new file mode 100644 index 0000000..9be3953 --- /dev/null +++ b/CSES Problem Set/Repetitions.cpp @@ -0,0 +1,93 @@ +/* Problem URL: https://cses.fi/problemset/task/1069 */ + +#include + +using namespace std; + +#define V vector + +#define rmin(a, b) a = min(a, b) +#define rmax(a, b) a = max(a, b) + +#define rep(i, lim) for (size_t i = 0; i < (lim); i++) +#define nrep(i, s, lim) for (size_t i = s; i < (lim); i++) + +#define repv(i, v) for (auto &i : (v)) +#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; } +#define sortv(v) sort(v.begin(), v.end()) +#define all(v) (v).begin(), (v).end() + +using vi = vector; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &vec)->ostream& { + for (auto &i : vec) { + os << i[0]; + for (size_t j = 1; j < i.size(); j++) { + os << ' ' << i[j]; + } + os << '\n'; + } + return os; +} + +template +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + string a; + cin >> a; + + int count = 1; + int maximus = 1; + + nrep(i, 1, a.size()) { + if (a[i - 1] == a[i]) { + count++; + rmax(maximus, count); + } else { + count = 1; + } + } + + cout << maximus << '\n'; +} diff --git a/CSES Problem Set/Weird Algorithm.cpp b/CSES Problem Set/Weird Algorithm.cpp new file mode 100644 index 0000000..e864ce9 --- /dev/null +++ b/CSES Problem Set/Weird Algorithm.cpp @@ -0,0 +1,90 @@ +/* Problem URL: https://cses.fi/problemset/task/1068 */ + +#include + +using namespace std; + +#define V vector + +#define rmin(a, b) a = min(a, b) +#define rmax(a, b) a = max(a, b) + +#define rep(i, lim) for (size_t i = 0; i < (lim); i++) +#define nrep(i, s, lim) for (size_t i = s; i < (lim); i++) + +#define repv(i, v) for (auto &i : (v)) +#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; } +#define sortv(v) sort(v.begin(), v.end()) +#define all(v) (v).begin(), (v).end() + +using vi = vector; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &vec)->ostream& { + for (auto &i : vec) { + os << i[0]; + for (size_t j = 1; j < i.size(); j++) { + os << ' ' << i[j]; + } + os << '\n'; + } + return os; +} + +template +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + ll n; + cin >> n; + + while (n != 1) { + cout << n << ' '; + if (n & 1) { + n = n * 3 + 1; + } else { + n /= 2; + } + } + + cout << 1 << '\n'; +}