diff --git a/algorithms/binary_search/choyunju/BJ_1477.java b/algorithms/binary_search/choyunju/BJ_1477.java new file mode 100644 index 0000000..65a7669 --- /dev/null +++ b/algorithms/binary_search/choyunju/BJ_1477.java @@ -0,0 +1,57 @@ +import java.io.*; +import java.util.*; + +class BJ_1477 { + static int[] arr; // 휴게소의 위치 배열 + static int[] diffDistance; //각 휴게소 별 거리차이 배열 + public static void main(String[] args) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer token = new StringTokenizer(reader.readLine()); + int N = Integer.parseInt(token.nextToken()); + int M = Integer.parseInt(token.nextToken()); + int L = Integer.parseInt(token.nextToken()); + //고속도로의 양 끝인 0과 L을 추가하기 위해 크기를 N+2로 지정 + arr = new int[N+2]; + arr[0] = 0; + arr[N+1] = L; + diffDistance = new int[N+1]; + token = new StringTokenizer(reader.readLine()); + for(int i=1; i<=N; i++) { + arr[i] = Integer.parseInt(token.nextToken()); + } + Arrays.sort(arr); + + //각 휴게소 별 거리의 차이를 구한다. + for(int i=0; i<=N; i++) { + diffDistance[i] = arr[i+1] - arr[i]; + } + + + // 휴게소의 위치는 1~(L-1) 사이에 위치 + int left = 1; + int right = L-1; + int result = 0; + + while(left <= right) { + int mid = (left+right)/2; + int count = 0; + for(int i=0; i<=N; i++) { + count += diffDistance[i]/mid; + // 0으로 나누어 떨어진 경우 이미 휴게소가 1개 지어진 경우이므로 -1을 해준다. + if(diffDistance[i] % mid == 0) { + count--; + } + } + + if(count <= M) { + right = mid-1; + result = mid; + } else { + left = mid+1; + + } + } + System.out.println(result); + + } +} \ No newline at end of file diff --git a/algorithms/binary_search/choyunju/BJ_20444.java b/algorithms/binary_search/choyunju/BJ_20444.java new file mode 100644 index 0000000..579ac79 --- /dev/null +++ b/algorithms/binary_search/choyunju/BJ_20444.java @@ -0,0 +1,34 @@ +import java.io.*; +import java.util.*; + +class BJ_20444 { + public static void main(String[] args) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer token = new StringTokenizer(reader.readLine()); + long N = Long.parseLong(token.nextToken()); + long K = Long.parseLong(token.nextToken()); + + long left = 0; + long right = N/2; + boolean isFlag = false; + while(left <= right) { + long mid = (left+right)/2; + long count = (mid+1) * (N-mid+1); + + if(count < K) { + left = mid+1; + } else if(count > K) { + right = mid-1; + } else { + isFlag = true; + break; + } + } + + if(isFlag) { + System.out.println("YES"); + } else { + System.out.println("NO"); + } + } +} \ No newline at end of file diff --git a/algorithms/binary_search/choyunju/BJ_2110.java b/algorithms/binary_search/choyunju/BJ_2110.java new file mode 100644 index 0000000..2b9b830 --- /dev/null +++ b/algorithms/binary_search/choyunju/BJ_2110.java @@ -0,0 +1,37 @@ +import java.io.*; +import java.util.*; + +class Main { + public static void main(String[] args) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer token = new StringTokenizer(reader.readLine()); + int N = Integer.parseInt(token.nextToken()); + int M = Integer.parseInt(token.nextToken()); + int[] arr = new int[N]; + for(int i=0; i= index) { + count++; + index = arr [i] + mid; + } + } + if(count >= M-1) { + left = mid+1; + result = mid; + } else { + right = mid-1; + } + } + System.out.println(result); + } +} \ No newline at end of file diff --git a/algorithms/binary_search/choyunju/BJ_2470.java b/algorithms/binary_search/choyunju/BJ_2470.java new file mode 100644 index 0000000..18a9aac --- /dev/null +++ b/algorithms/binary_search/choyunju/BJ_2470.java @@ -0,0 +1,47 @@ +import java.io.*; +import java.util.*; + +class BJ_2470 { + static int[] arr; + static int min = Integer.MAX_VALUE; + static int a, b; + + public static void main(String[] args) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(reader.readLine()); + arr = new int[N]; + StringTokenizer token = new StringTokenizer(reader.readLine()); + for(int i=0; i Math.abs(diff)) { + min = Math.abs(diff); + a = arr[start]; + b = arr[end]; + } + //두 용액의 합이 음수인 경우 + if(diff < 0) { + start++; + } + //두 용액의 합이 양수인 경우 + else if(diff > 0){ + end--; + } + else { + break; + } + } + System.out.println(a + " " + b); + } +} \ No newline at end of file diff --git a/algorithms/binary_search/choyunju/BJ_2473.java b/algorithms/binary_search/choyunju/BJ_2473.java new file mode 100644 index 0000000..b8bfa2c --- /dev/null +++ b/algorithms/binary_search/choyunju/BJ_2473.java @@ -0,0 +1,46 @@ +import java.io.*; +import java.util.*; + +class BJ_2473 { + public static void main(String[] args) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(reader.readLine()); + long[] arr = new long[N]; + StringTokenizer token = new StringTokenizer(reader.readLine()); + for(int i=0; i Math.abs(sum)) { + a = fix; + b = arr[left]; + c = arr[right]; + min = Math.abs(sum); + } + + if(sum < 0) { + left++; + } else if(sum > 0) { + right--; + } else { + System.out.println(a + " " + b + " " + c); + System.exit(0); + } + } + } + System.out.println(a + " " + b + " " + c); + } +} \ No newline at end of file