목록너비 우선 탐색 (22)
정화 코딩

https://www.acmicpc.net/problem/14502 #include #include #include using namespace std;int n, m, ans;vector> a;int dx[] = {1, -1, 0, 0};int dy[] = {0, 0, 1, -1};int bfs() { queue> q; vector> vst(n, vector(m, 0)); for (int i = 0; i = 0 && nxti = 0 && nxtj > n >> m; a = vector>(n, vector(m)); for (int i = 0; i > a[i][j]; } } dfs(0, 0, -1); cout 백트래킹으로 3개의 벽을 놓는 모든 경우를 ..

https://www.acmicpc.net/problem/16236 #include #include #include #include using namespace std;int n, curs, cnt, time;vector> m;int dx[] = {1, -1, 0, 0};int dy[] = {0, 0, 1, -1};vector targetf(int si, int sj) { vector> vst(n, vector(n, -1)); queue> q; vector> fish; q.emplace(si, sj); vst[si][sj] = 0; while (!q.empty()) { int curi = q.front().first; int curj = q.fro..

https://www.acmicpc.net/problem/23817 이 문제 풀 때 고수들이 옆에 있었어서 그들이 걍 다 해줌. 저는 풀이를 듣고 음 그렇구나. 천재다. 구현해볼게. 했음다. 첫번째 풀이. vst 배열: 현재 위치 (i, j) + 어느어느식당 방문했는지 (길이가 20인 비트스트링) 길이가 20인 비트스트링 → 2^20 하면 너무 큼 → 근데 어차피 최대가 5개 켜지는 거임 → 2^20 중에 안 쓰는 게 너무 많음 (어떤 걸 안 쓰는지 모름) → map 이용 vector>> → 최단 거리를 두번째 int에 저장하는 셈 vector>> (= vector>>) → 방문 했는지 안 했는지를 bool에 저장하는 셈 근데 이렇게 하면 터짐... 두번째 풀이.모든 식당과 식당 (+시작점) 사이의 거..

https://www.acmicpc.net/problem/12851 #include #include using namespace std;int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; int maxs = 100001; vector vst = vector(maxs, false); int timea = 0; int cnt = 0; queue> q; q.emplace(n, 0); vst[n] = true; while (!q.empty()) { int cur = q.front().first; int t..

https://www.acmicpc.net/problem/16953 #include #include #include using namespace std;int INTMAX = 1000000000;int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long a, b; cin >> a >> b; queue> q; q.emplace(a, 0); int ans = -1; while (!q.empty()) { long long x = q.front().first; int cnt = q.front().second; q.pop(); if (x..

https://www.acmicpc.net/problem/2206 #include #include #include using namespace std;int dx[] = {1, -1, 0, 0};int dy[] = {0, 0, 1, -1};int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector> g(n, vector(m)); vector> chk(n, vector(m, 0)); for (int i = 0; i > s; for (int j = 0; j > q; // {x index, y index, didBreak, coun..

https://www.acmicpc.net/problem/13549 #include #include #include using namespace std;bool vst[300001];int dx[] = {1, -1};int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; queue> q; int cur, cnt; bool fin = false; q.emplace(n, 0); vst[n + 100000] = true; while (!fin) { cur = q.front().first; cnt = q.front()...

https://www.acmicpc.net/problem/9328 #include #include #include using namespace std;int dx[] = {1, -1, 0, 0};int dy[] = {0, 0, 1, -1};int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc; cin >> tc; while (tc--) { int h, w; cin >> h >> w; vector m(h); vector> chk(h, vector(w, false)); vector open(26, false); queue>..