From 7af718d23c4cb3590f870d81124b496fb1e10aba Mon Sep 17 00:00:00 2001 From: mong3125 Date: Thu, 21 Mar 2024 02:04:05 +0900 Subject: [PATCH 1/2] =?UTF-8?q?BOJ1920=5F=EC=88=98=EC=B0=BE=EA=B8=B0=20jav?= =?UTF-8?q?a=20solution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\210\230\354\260\276\352\270\260.java" | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 "mong3125/\354\235\264\353\266\204\355\203\220\354\203\211/BOJ1920_\354\210\230\354\260\276\352\270\260.java" diff --git "a/mong3125/\354\235\264\353\266\204\355\203\220\354\203\211/BOJ1920_\354\210\230\354\260\276\352\270\260.java" "b/mong3125/\354\235\264\353\266\204\355\203\220\354\203\211/BOJ1920_\354\210\230\354\260\276\352\270\260.java" new file mode 100644 index 0000000..1cd5ead --- /dev/null +++ "b/mong3125/\354\235\264\353\266\204\355\203\220\354\203\211/BOJ1920_\354\210\230\354\260\276\352\270\260.java" @@ -0,0 +1,46 @@ +package 이진탐색; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class BOJ1920_수찾기 { + + static int[] A; + static int[] targets; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + A = new int[N]; + + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 0; i < A.length; i++) { + A[i] = Integer.parseInt(st.nextToken()); + } + + int M = Integer.parseInt(br.readLine()); + targets = new int[M]; + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < targets.length; i++) { + targets[i] = Integer.parseInt(st.nextToken()); + } + + Arrays.sort(A); + + for (int i = 0; i < targets.length; i++) { + int now = targets[i]; + System.out.println(binary(0, A.length - 1, now) ? 1 : 0); + } + } + + public static boolean binary(int from, int to, int n) { + if (from > to) return false; + int mid = (from + to) / 2; + + if (A[mid] == n) return true; + else if (A[mid] > n) return binary(from, mid - 1, n); + else return binary(mid + 1, to, n); + } +} From 08e3f4701542aa1abdec5f6e2d1f3f3834b6b102 Mon Sep 17 00:00:00 2001 From: mong3125 Date: Thu, 21 Mar 2024 02:04:18 +0900 Subject: [PATCH 2/2] =?UTF-8?q?BOJ1920=5F=EC=88=98=EC=B0=BE=EA=B8=B0=20jav?= =?UTF-8?q?a=20solution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BOJ1920_\354\210\230\354\260\276\352\270\260.java" | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git "a/mong3125/\354\235\264\353\266\204\355\203\220\354\203\211/BOJ1920_\354\210\230\354\260\276\352\270\260.java" "b/mong3125/\354\235\264\353\266\204\355\203\220\354\203\211/BOJ1920_\354\210\230\354\260\276\352\270\260.java" index 1cd5ead..c3e05b2 100644 --- "a/mong3125/\354\235\264\353\266\204\355\203\220\354\203\211/BOJ1920_\354\210\230\354\260\276\352\270\260.java" +++ "b/mong3125/\354\235\264\353\266\204\355\203\220\354\203\211/BOJ1920_\354\210\230\354\260\276\352\270\260.java" @@ -1,12 +1,10 @@ -package 이진탐색; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; -public class BOJ1920_수찾기 { +public class Main { static int[] A; static int[] targets;