Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commitf2ac1662504c72122bf9b77fe265095b58dab575 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-04-10 09:48:06 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-04-10 09:48:06 +0300
Files90030cef9c740ce895c61e50bd3726cec2944f4a
uni-projects-f2ac1662504c72122bf9b77fe265095b58dab575.tar
uni-projects-f2ac1662504c72122bf9b77fe265095b58dab575.tar.gz
uni-projects-f2ac1662504c72122bf9b77fe265095b58dab575.zip
Parentfe5a64bc48dd8b440fe13883f47c8fe5938ba080 (diff)
[DAA/E1] Added work from first exam from yesterday
diff --git a/Year 2/Design and analysis of algorithms/Practicum/Exam1/1-Flowers.cpp b/Year 2/Design and analysis of algorithms/Practicum/Exam1/1-Flowers.cpp
new file mode 100644
index 0000000..9421332
--- /dev/null
+++ b/Year 2/Design and analysis of algorithms/Practicum/Exam1/1-Flowers.cpp
@@ -0,0 +1,25 @@
+#include <cstdio>
+#include <cmath>
+#include <vector>
+#include <algorithm>
+using namespace std;
+
+int main() {
+ int K = 0, N = 0;
+ scanf("%d %d", &N, &K);
+ vector<int> f;
+ int temp = 0;
+ for (int i = 0; i < N; i++) {
+ scanf("%d", &temp);
+ f.push_back(temp);
+ }
+
+ sort(f.rbegin(), f.rend());
+ long S = 0, p = 1;
+ for (int i = 0; i < f.size(); i++) {
+ if (i == K * p) p++;
+ S += p * f[i];
+ }
+
+ printf("%ld", S);
+}
diff --git a/Year 2/Design and analysis of algorithms/Practicum/Exam1/2-Shots.cpp b/Year 2/Design and analysis of algorithms/Practicum/Exam1/2-Shots.cpp
new file mode 100644
index 0000000..24dadf9
--- /dev/null
+++ b/Year 2/Design and analysis of algorithms/Practicum/Exam1/2-Shots.cpp
@@ -0,0 +1,31 @@
+#include <cstdio>
+#include <cmath>
+#include <vector>
+#include <algorithm>
+using namespace std;
+
+int main() {
+ int N = 0;
+ scanf("%d", &N);
+ vector<long> m;
+ long temp = 0;
+ for (int i = 0; i < N; i++) {
+ scanf("%ld", &temp);
+ m.push_back(temp);
+ }
+
+ int l = 0, r = N - 1;
+ long lalc = 0, ralc = 0;
+ long tot = 0;
+ while (l <= r) {
+ if (lalc < ralc)
+ lalc += m[l++];
+ else
+ ralc += m[r--];
+ if (lalc == ralc) {
+ tot = (l - 1 - r) + N;
+ }
+ }
+
+ printf("%ld", tot);
+}
diff --git a/Year 2/Design and analysis of algorithms/Practicum/Exam1/3-Popcorn.cpp b/Year 2/Design and analysis of algorithms/Practicum/Exam1/3-Popcorn.cpp
new file mode 100644
index 0000000..fefd49c
--- /dev/null
+++ b/Year 2/Design and analysis of algorithms/Practicum/Exam1/3-Popcorn.cpp
@@ -0,0 +1,42 @@
+#include <cstdio>
+#include <cmath>
+#include <vector>
+#include <algorithm>
+using namespace std;
+
+int main() {
+ int K = 0, N = 0, S = 1;
+ scanf("%d %d %d", &N, &K, &S);
+ vector<int> p;
+ int temp = 0;
+ for (int i = 0; i < N; i++) {
+ scanf("%d", &temp);
+ p.push_back(temp);
+ }
+
+ for (int i = 0; i < p.size(); i++) {
+ p[i] = p[i] / S + (p[i] % S > 0);
+ if (i > 0) {
+ p[i] += p[i-1];
+ }
+ }
+
+ int t = 2000000000;
+ for (int i = 0, k = K; i < p.size(); i++) {
+ k = K;
+ for (int j = 0, mod = 0; j < p.size(); j++) {
+ if (k < 0) {
+ break;
+ }
+ if (p[j] - mod >= p[i]) {
+ k--;
+ mod = p[j];
+ }
+ }
+ if (k >= 0) {
+ t = min(t, p[i]);
+ }
+ }
+
+ printf("%d", t);
+}
diff --git a/Year 2/Design and analysis of algorithms/Practicum/Exam1/README.md b/Year 2/Design and analysis of algorithms/Practicum/Exam1/README.md
new file mode 100644
index 0000000..dc1377a
--- /dev/null
+++ b/Year 2/Design and analysis of algorithms/Practicum/Exam1/README.md
@@ -0,0 +1,8 @@
+# [Exam 1](https://www.hackerrank.com/1-35)
+
+|#|Exercise|Difficulty|Score|
+|-|--------|----------|-----|
+|1|[Flowers](https://www.hackerrank.com/contests/1-35/challenges/challenge-4047)|Easy|100|
+|2|[Shots](https://www.hackerrank.com/contests/1-35/challenges/challenge-4045)|Medium|100|
+|3|[Popcorn](https://www.hackerrank.com/contests/1-35/challenges/challenge-4046)|Medium|15|
+|4|[Meetup](https://www.hackerrank.com/contests/1-35/challenges/challenge-4049)|Hard|0|