queue
This commit is contained in:
parent
07567e4c8a
commit
c8470bb8dc
|
@ -1,5 +1,4 @@
|
|||
#include <cstdint>
|
||||
#include <deque>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <numeric>
|
||||
|
|
12
2019/15.cpp
12
2019/15.cpp
|
@ -1,5 +1,5 @@
|
|||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <queue>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
|
@ -70,9 +70,11 @@ auto Compute(std::map<Coord, ValueType> world) -> std::pair<int, int> {
|
|||
int part1 = -1;
|
||||
int part2 = -1;
|
||||
|
||||
for (std::deque<std::pair<int, Coord>> todo {{0,start}};
|
||||
!todo.empty();
|
||||
todo.pop_front())
|
||||
for (
|
||||
std::queue<std::pair<int, Coord>> todo
|
||||
{decltype(todo)::container_type{{0,start}}};
|
||||
!todo.empty();
|
||||
todo.pop())
|
||||
{
|
||||
auto [steps, here] = todo.front();
|
||||
if (Coord{0,0} == here) part1 = steps;
|
||||
|
@ -81,7 +83,7 @@ auto Compute(std::map<Coord, ValueType> world) -> std::pair<int, int> {
|
|||
for (auto fn : moves) {
|
||||
auto next = fn(here);
|
||||
if (world.erase(next)) {
|
||||
todo.emplace_back(steps+1, next);
|
||||
todo.emplace(steps+1, next);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <string>
|
||||
#include <tuple>
|
||||
#include <bitset>
|
||||
#include <deque>
|
||||
#include <queue>
|
||||
#include <cctype>
|
||||
#include <queue>
|
||||
#include <map>
|
||||
|
@ -56,11 +56,12 @@ auto FindDistancesFrom(
|
|||
) {
|
||||
std::map<char, std::pair<std::int64_t, Doors>> result;
|
||||
|
||||
std::deque<std::tuple<std::int64_t, Coord, Doors>> todo {{0, start, {}}};
|
||||
std::queue<std::tuple<std::int64_t, Coord, Doors>> todo;
|
||||
todo.push({0, start, {}});
|
||||
|
||||
std::set<Coord> seen;
|
||||
|
||||
for (; !todo.empty(); todo.pop_front()) {
|
||||
for (; !todo.empty(); todo.pop()) {
|
||||
auto [steps, here, doors] = todo.front();
|
||||
|
||||
// Don't visit the same coordinate twice
|
||||
|
@ -82,7 +83,7 @@ auto FindDistancesFrom(
|
|||
|
||||
// Visit all neighbors
|
||||
for (auto const fn : directions) {
|
||||
todo.emplace_back(steps+1, fn(here), doors);
|
||||
todo.emplace(steps+1, fn(here), doors);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
14
2019/20.cpp
14
2019/20.cpp
|
@ -10,7 +10,7 @@
|
|||
#include <string>
|
||||
#include <tuple>
|
||||
#include <bitset>
|
||||
#include <deque>
|
||||
#include <queue>
|
||||
#include <cctype>
|
||||
#include <queue>
|
||||
#include <map>
|
||||
|
@ -64,12 +64,12 @@ auto FindDistancesFrom(
|
|||
Coord const start
|
||||
) {
|
||||
std::vector<std::pair<Name, std::int64_t>> result;
|
||||
|
||||
std::deque<std::pair<std::int64_t, Coord>> todo {{0, start}};
|
||||
|
||||
std::set<Coord> seen;
|
||||
|
||||
for (; !todo.empty(); todo.pop_front()) {
|
||||
for (
|
||||
std::queue<std::pair<std::int64_t, Coord>> todo
|
||||
{decltype(todo)::container_type{{{0, start}}}};
|
||||
!todo.empty();
|
||||
todo.pop()) {
|
||||
auto const [steps, here] = todo.front();
|
||||
|
||||
// Don't visit the same coordinate twice
|
||||
|
@ -86,7 +86,7 @@ auto FindDistancesFrom(
|
|||
|
||||
// Visit all neighbors
|
||||
for (auto const fn : directions) {
|
||||
todo.emplace_back(steps+1, fn(here));
|
||||
todo.emplace(steps+1, fn(here));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
{
|
||||
"version": 2,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "preset",
|
||||
"displayName": "Configure preset using toolchain file",
|
||||
"description": "Sets Ninja generator, build and install directory",
|
||||
"generator": "Ninja",
|
||||
"binaryDir": "${sourceDir}/out/build/${presetName}",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug",
|
||||
"CMAKE_TOOLCHAIN_FILE": "",
|
||||
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user