From 96a34b6a02b42edf042e3714d04dab2f39a5f989 Mon Sep 17 00:00:00 2001 From: mong3125 Date: Thu, 28 Mar 2024 23:36:49 +0900 Subject: [PATCH 1/2] =?UTF-8?q?BOJ1243=5F=EC=9D=B4=EC=A7=84=ED=83=90?= =?UTF-8?q?=EC=83=89=20java=20solution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\203\200\353\240\210\354\212\250.java" | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 "mong3125/\354\235\264\354\247\204\355\203\220\354\203\211/BOJ2343_\352\270\260\355\203\200\353\240\210\354\212\250.java" diff --git "a/mong3125/\354\235\264\354\247\204\355\203\220\354\203\211/BOJ2343_\352\270\260\355\203\200\353\240\210\354\212\250.java" "b/mong3125/\354\235\264\354\247\204\355\203\220\354\203\211/BOJ2343_\352\270\260\355\203\200\353\240\210\354\212\250.java" new file mode 100644 index 0000000..6f357e2 --- /dev/null +++ "b/mong3125/\354\235\264\354\247\204\355\203\220\354\203\211/BOJ2343_\352\270\260\355\203\200\353\240\210\354\212\250.java" @@ -0,0 +1,66 @@ +package 이진탐색; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.IOException; +import java.util.StringTokenizer; + +public class BOJ2343_기타레슨 { + + static int N; + static int M; + static int[] lectures; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + lectures = new int[N]; + st = new StringTokenizer(br.readLine()); + + int sum = 0; + int max = 0; + for(int i = 0; i < N; i++) { + lectures[i] = Integer.parseInt(st.nextToken()); + sum += lectures[i]; + max = Math.max(max, lectures[i]); + } + + // 블루레이의 크기는 max부터 sum 사이 일것이다. + int result = minimumBlueray(max, sum); + + System.out.println(result); + } + + public static int minimumBlueray(int start, int end) { + if (start < end) return -1; + + int mid = (start + end) / 2; + + if (can(mid)) { + int more = minimumBlueray(start, mid - 1); + return more != -1 ? more : mid; + } + else return minimumBlueray(mid + 1, end); + } + + public static boolean can(int blueray) { + int count = M; + int i = 0; + int stack = blueray; + while (count > 0) { + while (stack - lectures[i] > 0) { + if (i == N) return true; + stack -= lectures[i]; + i++; + } + + stack = blueray; + count--; + } + + return false; + } +} From 3db11137f51e477ab24ed01b17811c7532a4b493 Mon Sep 17 00:00:00 2001 From: mong3125 Date: Tue, 2 Apr 2024 02:35:04 +0900 Subject: [PATCH 2/2] =?UTF-8?q?BOJ1300=5FK=EB=B2=88=EC=A7=B8=EC=88=98=20ja?= =?UTF-8?q?va=20solution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\262\210\354\247\270\354\210\230.java" | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 "mong3125/\354\235\264\354\247\204\355\203\220\354\203\211/BOJ1300_K\353\262\210\354\247\270\354\210\230.java" diff --git "a/mong3125/\354\235\264\354\247\204\355\203\220\354\203\211/BOJ1300_K\353\262\210\354\247\270\354\210\230.java" "b/mong3125/\354\235\264\354\247\204\355\203\220\354\203\211/BOJ1300_K\353\262\210\354\247\270\354\210\230.java" new file mode 100644 index 0000000..a255a9c --- /dev/null +++ "b/mong3125/\354\235\264\354\247\204\355\203\220\354\203\211/BOJ1300_K\353\262\210\354\247\270\354\210\230.java" @@ -0,0 +1,34 @@ +package 이진탐색; + +import java.util.Scanner; + +public class BOJ1300_K번째수 { + static int n; + static int k; + static int answer; + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + n = sc.nextInt(); + k = sc.nextInt(); + + index(0, k); + System.out.println(answer); + } + + public static void index(int front, int back) { + if (front > back) return; + + int mid = (front + back) / 2; + int sum = 0; + for (int i = 1; i <= n; i++) { + sum += Math.min(mid / i, n); + } + + if (sum < k) { + index(mid + 1, back); + } else { + answer = mid; + index(front, mid - 1); + } + } +}