본문 바로가기

백준 알고리즘/BFS47

백준 16234번 C++ #include #include #include #include using namespace std; const int MAX = 51; int n, l, r; int map[MAX][MAX]; bool possible = false; int visited[MAX][MAX]; struct Move { int x, y; }; Move mv[4] = { {1,0}, {0,1}, {-1,0}, {0,-1} }; void bfs(int i, int j) { int sum = 0; queue q; vector temp; q.push(make_pair(i, j)); temp.push_back(make_pair(i, j)); sum += map[i][j]; visited[i][j] = 1; while (!q.empt.. 2019. 10. 9.
백준 5427번 C++ #include #include #include #include using namespace std; int const MAX = 1000; int w, h; string map[MAX]; vector firecopy; pair location; int visited[MAX][MAX]; struct Move { int x, y; }; Move mv[4] = { {-1,0},{1,0},{0,1},{0,-1} }; bool exitcheck(int i, int j) { if (i == 0 || i == h - 1 || j == 0 || j == w - 1) return true; else return false; } int bfs() { int day = 0; queue loc; loc.push(locati.. 2019. 8. 21.
백준 2251번 C++ #include #include #include #include #include using namespace std; const int MAX = 201; int water[MAX][MAX][MAX]; int A, B, C; vector answer; void bfs() { queue q; q.push(make_pair(make_pair(0, 0),C)); while (!q.empty()) { int a = q.front().first.first; int b = q.front().first.second; int c = q.front().second; q.pop(); if (water[a][b][c] == 1) continue; if (a == 0) answer.push_back(c); water[a][b.. 2019. 8. 20.
백준 1325번 C++ #include #include #include #include using namespace std; const int MAX = 10001; int n, m; vector trust[MAX]; vector answer; int visited[MAX]; int dfs(int i) { visited[i] = 0; for (int k = 0; k < trust[i].size(); k++) { int move = trust[i][k]; if (visited[move] == -1) visited[i] = visited[i] + dfs(move) + 1; } return visited[i]; } int main(void) { int maxvalue = -1; ios_base::sync_with_stdio(0); .. 2019. 8. 20.