본문 바로가기

백준 알고리즘/BFS47

아기상어 C++ #include #include #include using namespace std; const int MAX = 21; int map[MAX][MAX]; int n, atenumber = 0; int sharksize = 2; pair sharkloc; pair feed; int answer = 0; struct Move { int x, y; }; Move mv[4] = { { 1,0 },{ -1,0 },{ 0,1 },{ 0,-1 } }; void bfs(pair loc, int count) { int visited[MAX][MAX]; queue q; memset(visited, -1, sizeof(visited)); q.push(make_pair(0, loc)); visited[loc.first][l.. 2021. 1. 3.
연구소 C++ #include #include #include #include using namespace std; const int MAX = 8; int n, m; int lab[MAX][MAX]; int temp[MAX][MAX]; vector virus; vector empty_room; typedef struct { int x, y; }Move; Move mv[4] = { {1,0}, {0,1}, {-1,0}, {0,-1} }; void copy_lab() { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { temp[i][j] = lab[i][j]; } } } void bfs() { queue q; for(int i=0; i= 0 && mx < n &.. 2020. 11. 16.
백준 구슬 탈출 2 C++ #include #include #include using namespace std; const int MAX = 11; char board[MAX][MAX]; int n, m; pair r, b, hole; int visited[MAX][MAX][MAX][MAX]; int answer = -1; struct Move { int x, y; }; Move mv[4] = { {1,0},{-1,0},{0,1},{0,-1} }; void bfs() { memset(visited, -1, sizeof(visited)); queue q; q.push(make_pair(0,make_pair(r, b))); visited[r.first][r.second][b.first][b.second] = 1; while (!q.e.. 2019. 10. 18.
백준 연구소3 C++ #include #include #include #include #include using namespace std; const int MAX = 51; int lab[MAX][MAX]; int copylab[MAX][MAX]; int n, m; vector active; vector virus; int visited[MAX][MAX]; struct Move { int x, y; }; Move mv[4] = { {1,0},{-1,0},{0,1},{0,-1} }; int answer = 987654321; void checkfinish() { bool finish = true; int value = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++).. 2019. 10. 18.