[프로그래머스] 미로 탈출(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/159993 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include #include using namespace std;struct Point{ int y, x; int score; bool operator==(const Point& other) const { return y == other.y && x == other.x; } Point operator+(const Point& other) con..
[프로그래머스] 게임 맵 최단거리(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/1844 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include using namespace std;struct Point{ int y, x; Point operator+(const Point& other) const { return Point(y + other.y, x + other.x); } bool operator==(const Point& other) const { if..
BFS 구현(C++)
·
개발/알고리즘
#include #include #include #include #include using namespace std;/** 너비 우선 탐색으로 모든 노드를 순회하는 함수 solution()을 작성하세요.* 시작 노드는 정수형 start로 주어집니다. graph 배열은 [출발 노드, 도착 노드] 쌍이 들어 있는 배열입니다.* 반환값은 그래프의 시작 노드부터 모든 노드를 너비 우선 탐색한 경로가 순서대로 저장된 배열입니다.*/unordered_map> adjList;vector result;void bfs(int start){ unordered_set visited; queue q; // 시작 노드 방문 q.push(start); visited.insert(start); result.push_back(sta..
DFS 구현 (C++)
·
개발/알고리즘
#include #include #include #include using namespace std;/** 깊이 우선 탐색으로 모든 그래프의 노드를 순회하는 함수 solution()을 작성하시오* 시작노드는 문자형 start로 주어집니다. graph 배열은 [출발 노드, 도착 노드] 쌍들이 들어있는 배열입니다.* 반환값은 그래프의 시작 노드부터 모든 노드를 깊이 우선 탐색으로 탐색한 경로가 순서대로 저장된 배열입니다.*/unordered_map> adjList;vector result;unordered_set visited;void dfs(char node){ // 현재 노드를 방문 목록과 방문 경로에 추가 visited.insert(node); result.push_back(node); // 현재 노드..