Skip to content

Commit 309fdd5

Browse files
committed
did a problem I was stuck on and a new one
1 parent 2c3a8f3 commit 309fdd5

File tree

8 files changed

+153
-146
lines changed

8 files changed

+153
-146
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include "../../../helperFunctions.h"
2+
3+
using namespace std;
4+
5+
/*******************************************************************************************
6+
Link: https://dmoj.ca/problem/ccc22s3
7+
Points: 15/15
8+
Inspiration: https://www.geekedu.org/blogs/2022-waterloo-ccc-senior-problem-solution#toc-8
9+
*******************************************************************************************/
10+
11+
void goodSamples()
12+
{
13+
long long N, M, K;
14+
scanf("%lld %lld %lld", &N, &M, &K);
15+
vector<long long> result;
16+
17+
for (long long i = 0; i < N; ++i)
18+
{
19+
// How many notes we have remaining after the one on the current index
20+
long long remainingAfterThisIndex = N - i - 1;
21+
// The maximum number of good samples we can make, K - remainingAfterThisIndex just gives us how many we can add at this index, so if
22+
// K = 5 and remainingAfterThisIndex = 2 then we can add a MAXIMUM of 3, but if M = 2 then it limits it to just 2 more good samples
23+
long long currentMaxNotes = min(K - remainingAfterThisIndex, M);
24+
25+
// If we can't add any more samples then just exit
26+
if (currentMaxNotes <= 0)
27+
break;
28+
29+
long long value = 0;
30+
31+
// If we can still add distinct integers and we do have to add them then do so
32+
if (currentMaxNotes > i)
33+
{
34+
// Get either i + 1 or M, whichever one is smaller, M just limits it so it doesn't go past the highest note
35+
value = min(M, i + 1);
36+
currentMaxNotes = value;
37+
}
38+
else
39+
value = result[i - currentMaxNotes]; // Use a previous note
40+
result.push_back(value);
41+
// Update the number of good samples we've created so far
42+
K -= currentMaxNotes;
43+
}
44+
45+
if (K == 0 && result.size() == N)
46+
{
47+
for (long long i = 0; i < result.size(); ++i)
48+
printf("%lld ", result[i]);
49+
printf("\n");
50+
return;
51+
}
52+
printf("-1\n");
53+
}
54+
55+
int main()
56+
{
57+
goodSamples();
58+
return 0;
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
/*******************************************************************************************
6+
Link: https://dmoj.ca/problem/ccc05s3
7+
Points: 15/15
8+
Inspiration: https://github.com/kingMonkeh/CCC-Solutions/blob/main/2005%20S3.cpp
9+
*******************************************************************************************/
10+
11+
void quantumOperations()
12+
{
13+
int N, ARows, AColumns, BRows, BColumns;
14+
scanf("%d", &N);
15+
16+
vector<vector<int>> A, B;
17+
18+
scanf("%d %d", &ARows, &AColumns);
19+
A.resize(ARows, vector<int>(AColumns));
20+
for (int i = 0; i < ARows; ++i)
21+
for (int j = 0; j < AColumns; ++j)
22+
scanf("%d", &A[i][j]);
23+
24+
for (int i = 0; i < N - 1; ++i)
25+
{
26+
scanf("%d %d", &BRows, &BColumns);
27+
B.clear();
28+
B.resize(BRows, vector<int>(BColumns));
29+
for (int i = 0; i < BRows; ++i)
30+
for (int j = 0; j < BColumns; ++j)
31+
scanf("%d", &B[i][j]);
32+
33+
vector<vector<int>> ACopy = A;
34+
A.clear();
35+
A.resize(ARows * BRows, vector<int>(AColumns * BColumns));
36+
for (int j = 0; j < ACopy.size(); ++j)
37+
for (int k = 0; k < ACopy[j].size(); ++k)
38+
for (int m = 0; m < B.size(); ++m)
39+
for (int n = 0; n < B[m].size(); ++n)
40+
A[m + BRows * j][n + BColumns * k] = ACopy[j][k] * B[m][n];
41+
42+
ARows *= BRows;
43+
AColumns *= BColumns;
44+
}
45+
46+
int maximumElement = INT_MIN;
47+
int minimumElement = INT_MAX;
48+
int maximumRowSum = INT_MIN;
49+
int minimumRowSum = INT_MAX;
50+
int maximumColumnSum = INT_MIN;
51+
int minimumColumnSum = INT_MAX;
52+
53+
vector<int> rowSums(A.size(), 0);
54+
vector<int> columnSums(A[0].size(), 0);
55+
56+
for (int i = 0; i < A.size(); ++i)
57+
{
58+
for (int j = 0; j < A[i].size(); ++j)
59+
{
60+
maximumElement = max(maximumElement, A[i][j]);
61+
minimumElement = min(minimumElement, A[i][j]);
62+
63+
rowSums[i] += A[i][j];
64+
columnSums[j] += A[i][j];
65+
}
66+
}
67+
68+
for (int i = 0; i < rowSums.size(); ++i)
69+
{
70+
maximumRowSum = max(maximumRowSum, rowSums[i]);
71+
minimumRowSum = min(minimumRowSum, rowSums[i]);
72+
}
73+
74+
for (int i = 0; i < columnSums.size(); ++i)
75+
{
76+
maximumColumnSum = max(maximumColumnSum, columnSums[i]);
77+
minimumColumnSum = min(minimumColumnSum, columnSums[i]);
78+
}
79+
80+
printf("%d\n", maximumElement);
81+
printf("%d\n", minimumElement);
82+
printf("%d\n", maximumRowSum);
83+
printf("%d\n", minimumRowSum);
84+
printf("%d\n", maximumColumnSum);
85+
printf("%d\n", minimumColumnSum);
86+
}
87+
88+
int main()
89+
{
90+
quantumOperations();
91+
return 0;
92+
}

Solutions/Leetcode Solutions/medium/houseRobber.cpp

-38
This file was deleted.

Solutions/Leetcode Solutions/medium/longestSubstringWithoutRepeatingCharacters.cpp

-40
This file was deleted.

anki

-34.4 KB
Binary file not shown.

anki.cpp

+1-65
Original file line numberDiff line numberDiff line change
@@ -19,72 +19,8 @@ void iterativeInOrderTraversal(TreeNode *root)
1919
}
2020
}
2121

22-
void iterativePreOrderTraversal(TreeNode *root)
23-
{
24-
stack<TreeNode *> nextNodes;
25-
nextNodes.push(root);
26-
while (!nextNodes.empty())
27-
{
28-
root = nextNodes.top();
29-
nextNodes.pop();
30-
printf("%d ", root->val);
31-
if (root->right != nullptr)
32-
nextNodes.push(root->right);
33-
if (root->left != nullptr)
34-
nextNodes.push(root->left);
35-
}
36-
}
37-
38-
void iterativePostOrderTraversal(TreeNode *root)
39-
{
40-
stack<TreeNode *> nextNodes;
41-
while (!nextNodes.empty() || root != nullptr)
42-
{
43-
if (root != nullptr)
44-
{
45-
nextNodes.push(root);
46-
root = root->left;
47-
}
48-
else
49-
{
50-
TreeNode *temp = nextNodes.top()->right;
51-
if (temp == nullptr)
52-
{
53-
temp = nextNodes.top();
54-
nextNodes.pop();
55-
printf("%d ", temp->val);
56-
while (!nextNodes.empty() && temp == nextNodes.top()->right)
57-
{
58-
temp = nextNodes.top();
59-
nextNodes.pop();
60-
printf("%d ", temp->val);
61-
}
62-
}
63-
else
64-
root = temp;
65-
}
66-
}
67-
}
68-
69-
int jumpGame2(vector<int> nums)
70-
{
71-
int l = 0;
72-
int r = 0;
73-
int res = 0;
74-
while (r < nums.size() - 1)
75-
{
76-
int farthest = 0;
77-
for (int i = l; i <= r; ++i)
78-
farthest = max(farthest, nums[i] + i);
79-
l = r + 1;
80-
r = farthest;
81-
++res;
82-
}
83-
return res;
84-
}
85-
8622
int main()
8723
{
88-
cout << jumpGame2(vector<int>({2, 3, 1, 1, 4})) << endl;
24+
iterativeInOrderTraversal(createDefaultTree());
8925
return 0;
9026
}

problems.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <math.h>
1010
#include <set>
1111
#include <bits/stdc++.h>
12-
#include "Miscellaneous/helperFunctions.h"
12+
#include "helperFunctions.h"
1313

1414
using namespace std;
1515

@@ -2658,7 +2658,5 @@ int main()
26582658
vector<int> nums2({1, 1, 2, 2});
26592659
vector<vector<int>> nums2d({{4, 3, 1}, {6, 5, 2}, {9, 7, 3}});
26602660

2661-
displayVector(nums1);
2662-
26632661
return 0;
26642662
}

0 commit comments

Comments
 (0)