일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 컴공
- vector
- c++
- coding
- 백준
- 정석학술정보관
- 구현
- cs
- 오퍼레이팅시스템
- 컴퓨터공학과
- 문제풀이
- OS
- 그래프
- 자료구조
- 정석
- 컴공과
- 브루트포스
- 오에스
- Stack
- 알고리즘
- 너비우선탐색
- 개발
- 북리뷰
- DP
- bfs
- Operating System
- 스택
- Computer science
- 코테
- 코딩
- Today
- Total
목록bfs (15)
Little Jay
BFS 구현으로 풀 수 있는 문제 #include #define endl '\n' using namespace std; int dist[1000001]; bool check[1000001]; int q[1000000]; int f, s, g, u, d; /* * bfs 조건 분기는 0 f >> s >> g >> u >> d; int begin = 0; int end = 0; q[end++] = s; dist[s] = 0; check[s] = true; while (begin < end) { int now = q[begin++]; if (now + u = 1 && check[now - d] == false) { q[end++] = now - d; dist[now - d] = dist[n..
문제 조건에 아무 지역도 물에 잠기지 않을 수도 있다. 이 말을 듣고 음 그런군..... 이라고 생각을 했었는데 이것때문에 계속 틀렸다;;; 이 말은 즉슨 level이 0부터 시작될 수도 있다는거다 #include #include #include #include #include using namespace std; int n, safe, level; int map[101][101]; bool visited[101][101]; int map_copy[101][101]; vector v; const int dx[] = { 1, -1, 0, 0 }; const int dy[] = { 0, 0, 1, -1 }; void copy(int flood_level) { for (int i = 0; i < n; i++)..
간단한 BFS 문제이다. 오랜만에 무지성으로 풀고 한번에 통과했다 미로탐색이랑 유사한 문제이다 #include #include #include #include using namespace std; intt, l, sx, sy, fx, fy; int cnt[300][300]; bool visited[300][300]; int table[300][300]; const int dx[] = { 1, 2, 2, 1, -1, -2, -2, -1 }; const int dy[] = { 2, 1, -1, -2, -2, -1, 1, 2 }; int main() { cin >> t; while (t--) { cin >> l; memset(visited, 0, sizeof(visited)); for (int i = 0; i..
간단한 BFS 문제이다. 경로는 대부분 BFS를 돌리면 찾을 수 있으므로 BFS로 접근해서 풀었다 처음에는 변수를 올리면서 탐색을 했는데, 이렇게 하면 BFS를 다 돈 값이 나와서 어떻게 하나 고민을 했었는데, 그냥 다른 이차원 배열에 경로를 이동한 값을 넣어주면서 다니면 되는걸 깨달았다. #include #include #include #include using namespace std; int n, m; char maze[100][100]; int cnt[101][101]; bool visited[100][100]; const int dx[] = { 1, -1, 0, 0 }; const int dy[] = { 0, 0, 1, -1 }; int main() { ios::sync_with_stdio(fa..
기본적인 그래프문제 #include #include #include #include #include #include using namespace std; vector a[1001]; bool check[1001]; void dfs(int node) { check[node] = true; printf("%d ", node); for (int i = 0; i < a[node].size(); i++) { int next = a[node][i]; if (check[next] == false) { dfs(next); } } } void bfs(int start) { queue q; memset(check, false, sizeof(check)); check[start] = true; q.push(start); w..