본문 바로가기

BFS20

[백준][bfs] 14497 주난의 난 c++ 구현 목차https://www.acmicpc.net/problem/14497문제 문제 구현 방향bfs와 dfs를 활용하면 풀 수 있는 문제였다.bfs를 통해 경로를 계산해주고 dfs를 통해 퍼져나가는 파동을 구현해주면 된다.  코드 구현#include #include #include #include #include using namespace std;int dx[4] = {0, 0, 1, -1};int dy[4] = { 1, -1, 0, 0 };int N, M, startX, startY, endX, endY;char board[300][300] = { 0 };int visit[300][300] = { 0 };queue> q;//파동이 퍼지는 것을 위한 dfsvoid dfs(int x, int y, int .. 2024. 6. 27.
[백준][bfs] 13913 숨바꼭질4 c++ 구현 목차 https://www.acmicpc.net/problem/13913문제참고하면 도움될 만한 글https://be-senior-developer.tistory.com/118 [백준][bfs] 12851 숨바꼭질2 c++구현목차https://www.acmicpc.net/problem/12851문제  코드 구현#include #include #include #include #include using namespace std;int visit[100001] = { 0 }; //시간 카운트int N, K;int cnt[100001] = { 0 }; //방법 수 카운트int methods = 0;int secbe-senior-developer.tistory.com 잘못된 접근 방향아래코드와 같이 각 분기점마다.. 2024. 6. 26.
[백준][bfs] 12851 숨바꼭질2 c++구현 목차https://www.acmicpc.net/problem/12851문제  코드 구현#include #include #include #include #include using namespace std;int visit[100001] = { 0 }; //시간 카운트int N, K;int cnt[100001] = { 0 }; //방법 수 카운트int methods = 0;int sec = 0;vector track;void bfs() { queue q; q.push(N); visit[N] = 1; cnt[N] = 1; while (!q.empty()) { int t = q.front(); q.pop(); if (t == K) { return; } for (int next : {t * 2,.. 2024. 6. 25.
[백준][bfs] 12869 뮤탈리스크 c++구현 목차https://www.acmicpc.net/problem/12869문제 문제 구현 시 주의점#include #include #include#includeusing namespace std;int start2[2][2] = { {9, 3 }, { 3, 9 } };int start3[6][3] = { {9, 3, 1 }, {9, 1, 3}, {3, 9, 1}, {3, 1, 9}, {1, 3, 9}, {1, 9, 3} };struct SCV { vector scv; int depth;};vector scv;vector ans;void print(vector t) { for (int i = 0; i q; q.push({ scv, 0 }); int cnt = 0; while (!q.empty()) { .. 2024. 6. 20.
728x90