[프로그래머스] 리코쳇 로봇 C++
다시 풀었다. 마찬가지로 이전 코드와 비슷비슷하다! bfs인데 한 방향으로 쭈우욱 가면 된다. #include #include #include using namespace std; bool visit[101][101]; int mx[4] = {-1, 1, 0, 0}; int my[4] = {0, 0, -1, 1}; int bfs(int sx, int sy, int row, int col, vector board) { queue que; // x, y, depth que.push({{sx, sy}, 0}); visit[sx][sy] = true; while(!que.empty()) { int x = que.front().first.first; int y = que.front().first.second; i..
2024. 3. 22.
[프로그래머스] 미로 탈출 C++
다시 풀어보는 문제. 이번엔 정확성이 자꾸 틀려서.. 예전에 어떻게 풀었나 코드 보니 이번에 문제를 꼼꼼히 읽지 않았다. n x n 맵인줄 알았더니 row x col 맵이었다. 풀이는 마찬가지로 레버에서 bfs 돌면 된다. #include #include #include #include using namespace std; int mx[4] = {1, -1, 0, 0}; int my[4] = {0, 0, 1, -1}; bool visit[101][101]; int goal = 0; bool sVisit, eVisit; void bfs(int sx, int sy, int row, int col, vector& maps) { queue que; que.push({{sx, sy}, 0}); visit[sx][..
2024. 3. 22.