목록알고리즘 풀이/백준 (61)
하다보니
#include #define X first #define Y second using namespace std; int dx[4] = { 1,-1,0,0 }; int dy[4] = { 0,0,1,-1 }; int main() { int T;//테스트 케이스 cin >> T; while (T--) { int m, n, k;//가로길이, 세로길이, 배추 위치 cin >> m >> n >> k; int board[52][52] = { 0 }; int vis[52][52] = { false }; int a, b; int cnt = 0; queue Q; for (int i = 0; i > a >> b; board[b][a] = 1; } for (int i = 0; i < n; i++..
/* 수빈이는 현재 n, 동생은 k에 있따. x+1,x-1가능, 2*x가능. 수빈이와 동생의 위치가 주어졌을 때 수빈이가 동생을 찾을 수 있는 가장 빠른 시간이 몇 초 후인가. */ #include using namespace std; int dist[100002]; int main() { int n, k; cin >> n >> k; fill(dist, dist + 100001, -1); dist[n] = 0; queue Q; Q.push(n); while (dist[k] == -1) { int cur = Q.front(); Q.pop(); for (int i : {cur - 1, cur + 1, cur * 2}) { if (i 100000)continue; if (dist[i] != -..
#include #define X first #define Y second using namespace std; string board[1002]; int dist1[1002][1002];//불 전파 int dist2[1002][1002];//지훈이 이동 int dx[4] = { 1,-1,0,0 }; int dy[4] = { 0,0,1,-1 }; int main() { int r, c; cin >> r >> c; queue Q1; //불 queue Q2; //지훈이 for (int i = 0; i < r; i++) fill(dist1[i], dist1[i] + c,-1); for (int i = 0; i < r; i++)fill(dist2[i], dist2[i] + c, -1); for (int i = ..
#include #define X first #define Y second using namespace std; int board[1002][1002]; int visited[1002][1002]; int dx[4] = { 1,-1,0,0 }; int dy[4] = { 0,0,-1,1 }; int main() { int n, m; queue Q; cin >> m >> n; for (int i = 0; i > board[i][j]; if (board[i][j] == 1)Q.push({ i,j }); if (board[i][j] == 0)visited[i][j] = -1; } } while (!Q.empty()) { auto..
#include using namespace std; #define X first #define Y second string board[102]; int dist[102][102]; int n,m; int dx[4] = {1,0,-1,0}; int dy[4] = {0,1,0,-1}; int main(void){ ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for(int i = 0; i > board[i]; for(int i = 0; i < n; i++) fill(dist[i],dist[i]+m,-1); queue Q; Q.push({0,0}); dist[0][0] = 0; while(!Q.empty()){ auto cur = Q...
#include using namespace std; #define X first #define Y second int board[502][502]; bool visit[502][502]; int dx[4] = { 1,-1,0,0 }; int dy[4] = { 0,0,1,-1 }; int main() { int n, m; queue Q; vector v; cin >> n >> m; for (int i = 0; i > board[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int cnt = 0; if (board[i][j] == 1&&!vis..
#include using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); deque Q; int n, m; int ans = 0; cin >> n >> m; for (int i = 1; i > a; int idx = find(Q.begin(), Q.end(), a)-Q.begin(); while (Q.front() != a) { if (idx
#include using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); deque q; int n; cin >> n; while (n--) { string s; cin >> s; if (s == "push_front") { int t; cin >> t; q.push_front(t); } else if (s == "push_back") { int k; cin >> k; q.push_back(k); } else if (s == "front") { if (q.empty()) { cout
#include using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); queue Q; int n; cin >> n; for (int i = 1; i