백준 7562번 나이트의 이동
https://www.acmicpc.net/problem/7562 아이디어:1. 방향 dx, dy를 나이트의 이동에 맞게 변경하고 거리를 기록하는 BFSint dx[8] = { 2, 1, -1, -2, -2, -1, 1, 2 }; int dy[8] = { 1, 2, 2, 1, -1, -2, -2, -1 }; #include #include using namespace std;int board[301][301];int vis[301][301];int dx[8] = { 2, 1, -1, -2, -2, -1, 1, 2 };int dy[8] = { 1, 2, 2, 1, -1, -2, -2, -1 };int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ..
백준 7569번 토마토
https://www.acmicpc.net/problem/7569 아이디어:1.3차원 BFS7576번 토마토의 3차원 문제2. tuple 사용삽입 Q.push({ nx, ny, nz});cur 선언 tuple cur = Q.front();확인 get(cur) = cur의 1번째 값, get(cur) = cur의 2번째 값, get(cur) = cur의 3번째 값대입 ans = vis[get(cur)][get(cur)][get(cur)]; 배열 인덱스와 N, M, H의 순서에 주의3. 방향 dx, dy에 이어 int dz[6] = { 0, 0, 0, 0, 1, -1}; 추가가운데 익은 토마토를 기준으로 x, y, z 방향 처리4. 배열 인덱스 board[][][], vis[][][]와 N, M, H의 순서..
백준 1012번 유기농 배추
아이디어:1. BFS2. 시작점이 여러개이므로 2중 for문으로 순회하면서 시작점을 찾고 하나의 배추 무리씩 점검 및 BFS를 수행한다.3. board[][], vis[][]를 포함한 각 변수에 대한 초기화에 주의한다. #include #include using namespace std;int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t, n, m, k, i, j; cin >> t; int dx[4] = { 1, 0 , -1, 0 }; int dy[4] = { 0, 1 , 0, -1 }; while (t--) { int board[51][51]; int vis[51][51]; for (int i = 0; i > Q; int a..