From 62c29d52757e42584eecb0b7cf325ffc63c22136 Mon Sep 17 00:00:00 2001 From: KIM YUMIN <122423278+bbungbbaeng@users.noreply.github.com> Date: Sun, 23 Feb 2025 14:52:04 +0900 Subject: [PATCH 1/3] 25.02.23 --- yumin/25.02.23/14496.cpp | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 yumin/25.02.23/14496.cpp diff --git a/yumin/25.02.23/14496.cpp b/yumin/25.02.23/14496.cpp new file mode 100644 index 0000000..c273325 --- /dev/null +++ b/yumin/25.02.23/14496.cpp @@ -0,0 +1,55 @@ +/* +BFS 문제, 늘 먹던 맛 익숙한 맛. +*/ + +# include +# include +# include + +using namespace std; + +int main() { + ios::sync_with_stdio(false); + cin.tie(nullptr); + + int start, target; + cin >> start >> target; + + int n, m; + cin >> n >> m; + + vector> graph(n + 1); + + for (int i = 0; i < m; i++) { + int u, v; + cin >> u >> v; + graph[u].push_back(v); // u와 치환 가능한 문자 리스트에 v 추가 + graph[v].push_back(u); // v와 치환 가능한 문자 리스트에 u 추가 + } + + vector distance(n + 1, -1); // 각 문자까지의 치환 횟수를 저장할 벡터 + queue q; // BFS 할라고 만든 큐 + + distance[start] = 0; + q.push(start); + + while(!q.empty()) { + int current = q.front(); // 큐의 맨 앞에 있는 문자를 선택해주자. + q.pop(); // 그리고 선택한 문자를 큐에서 제거한다. + + if (current == target) { // 목표 문자에 도달할 경우 탐색을 종료한다. + break; + } + + // 현재 문자와 치환 가능한 모든 문자를 탐색해주자. + for (int next : graph[current]) { + if (distance[next] == -1) { // 아직 방문하지 않은 문자라면, + distance[next] = distance[current] + 1; // 다음 문자까지의 치환 횟수는 현재 문자까지의 치환 횟수 + 1. + q.push(next); // 다음 문자를 큐에 삽입하고 탐색 ㄱㄱ + } + } + } + + cout << distance[target] << "\n"; + return 0; +} From efc7cdac847a93b34b8b4c090f8259d026b0f3fb Mon Sep 17 00:00:00 2001 From: KIM YUMIN <122423278+bbungbbaeng@users.noreply.github.com> Date: Sun, 23 Feb 2025 15:01:39 +0900 Subject: [PATCH 2/3] 25.02.23 --- yumin/25.02.23/16953.cpp | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 yumin/25.02.23/16953.cpp diff --git a/yumin/25.02.23/16953.cpp b/yumin/25.02.23/16953.cpp new file mode 100644 index 0000000..7ee829c --- /dev/null +++ b/yumin/25.02.23/16953.cpp @@ -0,0 +1,44 @@ +/* +그리디로 풀었는데 문제 알고리즘 분류를 까보니 그래프..? +*/ + +# include + +using namespace std; + +int main() { + int a, b; + cin >> a >> b; + + int cnt = 0; + + while (b > a) { + /* + b의 가장 오른쪽 자리가 1인 경우, 오른쪽의 1을 제거하기 위해 10으로 나눠주고 연산 횟수를 1만큼 증가시켜주자. + */ + if (b % 10 == 1) { + b /= 10; + cnt++; + } + + /* + b가 짝수인 경우, 2로 나누어주고 연산 횟수를 1만큼 증가시켜주자. + */ + else if (b % 2 == 0) { + b /= 2; + cnt++; + } + + // 위 두 개의 조건을 모두 만족하지 않는 경우에는 더 이상 변환할 수 없으니까 반복 종료. + else { + break; + } + } + + if (b == a) + cout << cnt + 1 << "\n"; + else + cout << -1 << "\n"; + + return 0; +} From e90e27fc25daba5f595a19a4296ea3b6748316b8 Mon Sep 17 00:00:00 2001 From: KIM YUMIN <122423278+bbungbbaeng@users.noreply.github.com> Date: Sun, 23 Feb 2025 17:33:24 +0900 Subject: [PATCH 3/3] 25.02.23 --- yumin/25.02.23/13901.cpp | 94 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 yumin/25.02.23/13901.cpp diff --git a/yumin/25.02.23/13901.cpp b/yumin/25.02.23/13901.cpp new file mode 100644 index 0000000..0f0cfe4 --- /dev/null +++ b/yumin/25.02.23/13901.cpp @@ -0,0 +1,94 @@ +/* +구현이 싫어요 +*/ + +# include +# include + +using namespace std; + +int main() { + ios::sync_with_stdio(false); + cin.tie(nullptr); + + int r, c; + cin >> r >> c; + + vector> obstacle(r, vector(c, false)); + vector> visited(r, vector(c, false)); + + int k; + cin >> k; + + for (int i = 0; i < k; i++) { + int br, bc; + cin >> br >> bc; + obstacle[br][bc] = true; + } + + int sr, sc; + cin >> sr >> sc; + + vector order(4); + for (int i = 0; i < 4; i++) { + cin >> order[i]; + } + + vector> deltas(5); + deltas[1] = make_pair(-1, 0); + deltas[2] = make_pair(1, 0); + deltas[3] = make_pair(0, -1); + deltas[4] = make_pair(0, 1); + + int curIndex = 0; + int direction = order[curIndex]; + + int curR = sr, curC = sc; + visited[curR][curC] = true; + + // 로봇이 움직일 수 있는 동안 반복 ㄱㄱ + while (true) { + // 한 칸 이동할 다음 위치도 계산해주자. + int nextR = curR + deltas[direction].first; + int nextC = curC + deltas[direction].second; + + // 다음 위치가 방의 범위 내에 있고, 장애물도 없고, 아직 방문하지 않은 곳이라면 로봇이 다음 위치로 이동 쓩 + if (nextR >= 0 && nextR < r && nextC >= 0 && nextC < c && !obstacle[nextR][nextC] && !visited[nextR][nextC]) { + curR = nextR; + curC = nextC; + visited[curR][curC] = true; + continue; + } + + // 현재 방향으로 더 이상 이동할 수 없으므로, 지정된 다음 방향을 찾아보자. + else { + bool moved = false; // 새로운 방향으로 이동했는지 여부를 따지는 변수 + + // 새로운 방향과 위치 변수.. + for (int i = 1; i <= 4; i++) { + int newIndex = (curIndex + i) % 4; + int newDirection = order[newIndex]; + nextR = curR + deltas[newDirection].first; + nextC = curC + deltas[newDirection].second; + + // 해당 위치가 로봇이 갈 수 있는 곳이라면 또 ㄱㄱ + if (nextR >= 0 && nextR < r && nextC >= 0 && nextC < c && !obstacle[nextR][nextC] && !visited[nextR][nextC]) { + curIndex = newIndex; + direction = newDirection; + curR = nextR; + curC = nextC; + visited[curR][curC] = true; + moved = true; + break; + } + } + + // 4가지 방향으로 모두 이동할 수 없다면 반복 종료. + if (!moved) + break; + } + } + + cout << curR << " " << curC << "\n"; + return 0; +}