Skip to content

Commit 844df36

Browse files
committed
finished some flashcards and S1 from yesterday
1 parent d8a55ae commit 844df36

File tree

5 files changed

+384
-43
lines changed

5 files changed

+384
-43
lines changed

Contests/DMOJ Contests/OTHS Coding Competition 3 (CCC)/S1.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,25 @@ void the5thLaboratory()
4848
}
4949
else
5050
{
51+
// Get the triangle distance
52+
double distanceToPoint = hypot(abs(hidingSpotCoordinates.x - labCoordinates.x), abs(hidingSpotCoordinates.y - labCoordinates.y));
53+
5154
// Go all the way down
5255
distance = abs(hidingSpotCoordinates.z - labCoordinates.z);
5356
time += distance / 4;
5457

55-
// Get the distance remaining
56-
distance = hypot(abs(hidingSpotCoordinates.x - labCoordinates.x), abs(hidingSpotCoordinates.y - labCoordinates.y)) - (3 * time);
57-
58-
// Travel on flat ground
59-
time += abs(distance) / 2;
58+
double distanceCovered = time * 3;
59+
if (distanceToPoint - distanceCovered > 0)
60+
{
61+
time += (distanceToPoint - distanceCovered) / 2;
62+
}
6063
}
6164

6265
if (minimumTime == -1)
6366
minimumTime = time;
6467
else
6568
minimumTime = min(minimumTime, time);
69+
time = 0;
6670
}
6771

6872
printf("%f\n", minimumTime);
Binary file not shown.

anki

60.4 KB
Binary file not shown.

anki.cpp

+50-38
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,11 @@
22

33
using namespace std;
44

5-
void gates()
6-
{
7-
int numberOfGates;
8-
int numberOfPlanes;
9-
10-
scanf("%d", &numberOfGates);
11-
scanf("%d", &numberOfPlanes);
12-
13-
vector<int> planes(numberOfPlanes);
14-
set<int, greater<int>> gates;
15-
for (int i = 0; i < numberOfPlanes; ++i)
16-
scanf("%d", &planes[i]);
17-
for (int i = 1; i <= numberOfGates; ++i)
18-
gates.insert(i);
19-
20-
int numberOfPlanesAbleToDock = 0;
21-
for (int i = 0; i < numberOfPlanes; ++i)
22-
{
23-
auto gate = gates.lower_bound(planes[i]);
24-
if (gate == gates.end())
25-
break;
26-
gates.erase(*gate);
27-
++numberOfPlanesAbleToDock;
28-
}
29-
30-
printf("%d\n", numberOfPlanesAbleToDock);
31-
}
32-
335
int subarraySumEqualsK(vector<int> &nums, int k)
346
{
357
unordered_map<int, int> previousSums;
368
previousSums[0] = 1;
37-
int prefixSum;
9+
int prefixSum = 0;
3810
int numberOfSubarrays = 0;
3911

4012
for (int i = 0; i < nums.size(); ++i)
@@ -53,6 +25,27 @@ int subarraySumEqualsK(vector<int> &nums, int k)
5325
return numberOfSubarrays;
5426
}
5527

28+
bool wordBreak(string s, vector<string> wordDict)
29+
{
30+
vector<bool> dp(s.size() + 1, false);
31+
dp[dp.size() - 1] = true;
32+
33+
for (int i = s.size() - 1; i >= 0; --i)
34+
{
35+
for (int j = 0; j < wordDict.size(); ++j)
36+
{
37+
if (i + wordDict[j].size() <= s.size() && dp[i + wordDict[j].size()])
38+
{
39+
string curr = s.substr(i, wordDict[j].size());
40+
if (curr == wordDict[j])
41+
dp[i] = true;
42+
}
43+
}
44+
}
45+
46+
return dp[0];
47+
}
48+
5649
int deleteAndEarn(vector<int> &nums)
5750
{
5851
sort(nums.begin(), nums.end());
@@ -62,29 +55,48 @@ int deleteAndEarn(vector<int> &nums)
6255
for (int i = 0; i < nums.size(); ++i)
6356
{
6457
if (i == 0 || nums[i] != nums[i - 1])
58+
{
6559
numsPrime.push_back(nums[i]);
66-
++counts[nums[i]];
60+
counts[nums[i]] = 1;
61+
}
62+
else if (i > 0 && nums[i] == nums[i - 1])
63+
++counts[nums[i]];
6764
}
6865

6966
vector<int> dp(numsPrime.size(), 0);
70-
for (int i = 0; i < numsPrime.size(); ++i)
67+
dp[0] = numsPrime[0] * counts[numsPrime[0]];
68+
for (int i = 1; i < numsPrime.size(); ++i)
7169
{
7270
int value = numsPrime[i] * counts[numsPrime[i]];
73-
74-
if (i > 0 && numsPrime[i] - numsPrime[i - 1] > 1)
71+
if (numsPrime[i] - numsPrime[i - 1] > 1)
7572
value += numsPrime[i - 1];
76-
else if (i >= 2 && numsPrime[i] - numsPrime[i - 1] == 1)
77-
value += dp[i - 2];
78-
if (i > 0)
79-
dp[i] = max(dp[i - 1], value);
8073
else
81-
dp[i] = value;
74+
value = max(value + (i >= 2 ? numsPrime[i - 2] : 0), numsPrime[i - 1]);
75+
dp[i] = value;
8276
}
8377

8478
return dp[dp.size() - 1];
8579
}
8680

81+
void iterativePreOrderTraversal(TreeNode *root)
82+
{
83+
stack<TreeNode *> nextNodes;
84+
nextNodes.push(root);
85+
while (!nextNodes.empty())
86+
{
87+
TreeNode *curr = nextNodes.top();
88+
nextNodes.pop();
89+
printf("%d ", curr->val);
90+
91+
if (curr->right != nullptr)
92+
nextNodes.push(curr->right);
93+
if (curr->left != nullptr)
94+
nextNodes.push(curr->left);
95+
}
96+
}
97+
8798
int main()
8899
{
100+
iterativePreOrderTraversal(createDefaultTree());
89101
return 0;
90102
}

0 commit comments

Comments
 (0)