From 9e53247fd3880cdeb789b0db3929e6fc77559e33 Mon Sep 17 00:00:00 2001 From: kokeunho <95072015+kokeunho@users.noreply.github.com> Date: Mon, 30 Dec 2024 11:47:41 +0900 Subject: [PATCH] =?UTF-8?q?2024-12-30/=EC=88=A8=EB=B0=94=EA=BC=AD=EC=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kokeunho/README.md | 1 + .../13-kokeunho.java" | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 "kokeunho/\352\267\270\353\236\230\355\224\204 \355\203\220\354\203\211/13-kokeunho.java" diff --git a/kokeunho/README.md b/kokeunho/README.md index 15eb65a..0d9a69a 100644 --- a/kokeunho/README.md +++ b/kokeunho/README.md @@ -14,4 +14,5 @@ | 10차시 | 2024.11.30 | 자료구조 | [가운데를 말해요](https://www.acmicpc.net/problem/1655) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/36) | | 11차시 | 2024.12.21 | 그리디 알고리즘 | [회의실 배정](https://www.acmicpc.net/problem/1931) | [#43](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/43) | | 12차시 | 2024.12.25 | 그리디 알고리즘 | [크게 만들기](https://www.acmicpc.net/problem/2812) | [#45](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/45) | +| 13차시 | 2024.12.30 | 그래프 탐색 | [숨바꼭질](https://www.acmicpc.net/problem/1697) | [#47](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/47) | --- diff --git "a/kokeunho/\352\267\270\353\236\230\355\224\204 \355\203\220\354\203\211/13-kokeunho.java" "b/kokeunho/\352\267\270\353\236\230\355\224\204 \355\203\220\354\203\211/13-kokeunho.java" new file mode 100644 index 0000000..db159ec --- /dev/null +++ "b/kokeunho/\352\267\270\353\236\230\355\224\204 \355\203\220\354\203\211/13-kokeunho.java" @@ -0,0 +1,35 @@ +package org.example; + +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + int n = sc.nextInt(); + int k = sc.nextInt(); + int[] visited = new int[100001]; + Arrays.fill(visited, -1); + + Queue queue = new LinkedList<>(); + queue.add(n); + visited[n] = 0; + + while(!queue.isEmpty()) { + int current = queue.poll(); + + if(current == k) { + System.out.println(visited[current]); + break; + } + + for(int next : new int[]{current - 1, current + 1, current * 2}) { + if(next >= 0 && next <= 100000 && visited[next] == -1) { + visited[next] = visited[current] + 1; + queue.add(next); + } + } + + } + } +} \ No newline at end of file