• 문제 링크
19592번: 장난감 경주
당신을 포함한 N명의 참가자가 각자 자신의 장난감 자동차를 이용해 경주를 하는데, 트랙의 길이는 X 미터이다. 참가자는 1번부터 N번까지 번호가 매겨져 있고, 당신의 참가 번호는 N번이다. i번
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
static int n, x, y;
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int t = read();
StringBuilder sb = new StringBuilder();
while (t-- > 0) {
n = read();
x = read();
y = read();
int max = 0;
for (int i = 0; i < n - 1; i++)
max = Math.max(max, read());
if (max < (n = read())) sb.append("0\n");
else sb.append(binarySearch((double) x / max)).append("\n");
}
bw.write(sb.toString());
bw.flush();
}
private static int binarySearch(double key) {
int low = 1, high = y;
while (low <= high) {
int mid = (low + high) >>> 1;
if (1.0 + (double) (x - mid) / n < key) high = mid - 1;
else low = mid + 1;
}
return low > y ? -1 : low;
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 4796 캠핑 - Greedy / Java (0) | 2023.08.14 |
---|---|
[백준] 13777 Hunt The Rabbit - BinarySearch / Java (0) | 2023.08.13 |
[백준] 17124 두 개의 배열 - BinarySearch / Java (0) | 2023.08.11 |
[백준] 13702 이상한 술집 - BinarySearch / Java (0) | 2023.08.10 |
[백준] 18265 MooBuzz - BinarySearch / Java (0) | 2023.08.09 |
댓글