중점: 1. bfs 알고리즘 사용 2. vis에 +1을 하며 count, board 값 -1인지 확인 3. 마지막에 0이 있다면 impossible 출력 정답 코드: #include using namespace std; #define X first #define Y second int board[1005][1005]; int n, m; int dx[] = {1, 0 , -1, 0}; int dy[] = {0, 1, 0, -1}; int main(void){ ios::sync_with_stdio(0); cin.tie(0); cin >> m >> n; queue Q; int count = 0; for (int i = 0; i >..
coding-test
중점: 1. 3차원 배열에 대한 bfs 진행 2. dir: x, y, z에 대해서 각 방향 파악 3. m, n, h에 대해서 알맞게 배열 정답 코드: #include using namespace std; int dx[] = {1, -1, 0, 0, 0, 0}; int dy[] = {0, 0, 1, -1, 0, 0}; int dz[] = {0, 0, 0, 0, 1, -1}; int board[102][102][102]; int vis[102][102][102]; int m, n, h; int main(void){ ios::sync_with_stdio(0); cout.tie(0); cin >> m >> n >> h; int count = 0; queue Q; for (int i = 0; i < h; i++)..
중점: 1. 기본 bfs에서 dir에 대한 부분을 나이트의 이동 범위로 바꾸어서 진행한다. 정답 코드: #include using namespace std; #define X first #define Y second int dx[] = {2, 2, 1, 1, -2, -2, -1, -1}; int dy[] = {1, -1, 2, -2, 1, -1, 2, -2}; int board[302][302]; int vis[302][302]; int t, n, start_x, start_y, end_x, end_y; int main(void){ ios::sync_with_stdio(0); cin.tie(0); cin >> t; queue Q; while (t--) { cin >> n; for (int i = 0; i..
중점: 1. 4179번 문제와 동일한 로직 사용 2. 이때 test case가 있기 때문에 break시에 queue를 초기화 해야한다. 3. bool 값을 이용해서 출력 정답 코드: #include using namespace std; #define X first #define Y second int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; string board[1002]; int vis1[1002][1002]; int vis2[1002][1002]; int t, w, h; int main(void){ ios::sync_with_stdio(0); cin.tie(0); cin >> t; while (t--) { cin >> w >> h; queue Q1; qu..
중점: 1. 불에 대한 bfs와 사람에 대한 bfs를 두번 시행 2. 불에 대한 bfs를 먼저 시행 3. 사람에 대한 bfs를 시행 하는 경우 vis1에 대한 조건을 확인한다 (불이 먼저 옮겼는지에 대한 파악을 한다) 정답 코드: #include using namespace std; #define X first #define Y second string borad[1005]; int vis1[1005][1005]; int vis2[1005][1005]; int r, c; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int main(void){ ios::sync_with_stdio(0); cin.tie(0); cin >> r >> c; for (int i =..
중점: 1. bfs 알고리즘 사용 2. N, M 좌표까지 vis 값 +1 정답 코드: #include using namespace std; #define X first #define Y second string board[105]; int vis[105][105]; int n, m; int dx[] = {1, 0 , -1, 0}; int dy[] = {0, 1, 0, -1}; int main(void){ ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; //n, m값 입력 받음. for (int i = 0; i > board[i]; } vis[0][0] = 1; queue Q; Q.push({0, 0})..