Skip to content

Commit

Permalink
Update some programs
Browse files Browse the repository at this point in the history
  • Loading branch information
metopa committed Nov 20, 2019
1 parent e51c1df commit c23c4c2
Show file tree
Hide file tree
Showing 6 changed files with 507 additions and 510 deletions.
4 changes: 2 additions & 2 deletions epi_judge_cpp_solutions/calendar_rendering.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ int FindMaxSimultaneousEvents(const vector<Event>& A) {
// Builds an array of all endpoints.
vector<Endpoint> E;
for (const Event& event : A) {
E.emplace_back(Endpoint{event.start, true});
E.emplace_back(Endpoint{event.finish, false});
E.push_back({event.start, true});
E.push_back({event.finish, false});
}
// Sorts the endpoint array according to the time, breaking ties
// by putting start times before end times.
Expand Down
5 changes: 2 additions & 3 deletions epi_judge_cpp_solutions/gray_code.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "test_framework/test_failure.h"
#include "test_framework/timed_executor.h"

using std::make_unique;
using std::unique_ptr;
using std::unordered_set;
using std::vector;
Expand All @@ -16,9 +17,7 @@ bool DiffersByOneBit(int, int);

vector<int> GrayCode(int num_bits) {
vector<int> result({0});
DirectedGrayCode(
num_bits, unique_ptr<unordered_set<int>>{new unordered_set<int>{0}}.get(),
&result);
DirectedGrayCode(num_bits, make_unique<unordered_set<int>>(0).get(), &result);
return result;
}

Expand Down
5 changes: 2 additions & 3 deletions epi_judge_cpp_solutions/k_largest_in_heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ vector<int> KLargestInBinaryHeap(const vector<int>& A, int k) {
candidate_max_heap.pop();

if (int left_child_idx = 2 * candidate_idx + 1; left_child_idx < size(A)) {
candidate_max_heap.emplace(HeapEntry{left_child_idx, A[left_child_idx]});
candidate_max_heap.push({left_child_idx, A[left_child_idx]});
}
if (int right_child_idx = 2 * candidate_idx + 2;
right_child_idx < size(A)) {
candidate_max_heap.emplace(
HeapEntry{right_child_idx, A[right_child_idx]});
candidate_max_heap.push({right_child_idx, A[right_child_idx]});
}
}
return result;
Expand Down
3 changes: 1 addition & 2 deletions epi_judge_cpp_solutions/max_of_sliding_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ vector<TrafficElement> CalculateTrafficVolumes(const vector<TrafficElement>& A,
while (traffic_info.time - sliding_window.Head().time > w) {
sliding_window.Dequeue();
}
maximum_volumes.emplace_back(
TrafficElement{traffic_info.time, sliding_window.Max().volume});
maximum_volumes.push_back({traffic_info.time, sliding_window.Max().volume});
}
return maximum_volumes;
}
Expand Down
2 changes: 1 addition & 1 deletion epi_judge_python_solutions/is_list_cyclic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def cycle_len(end):
return step

fast = slow = head
while fast and fast.next and fast.next.next:
while fast and fast.next:
slow, fast = slow.next, fast.next.next
if slow is fast:
# Finds the start of the cycle.
Expand Down
Loading

0 comments on commit c23c4c2

Please sign in to comment.