• 문제 링크
31066번: 비 오는 날
$T$개의 줄에 걸쳐, $i$번째 줄에는 $i$번째 테스트 케이스의 답에 해당하는 정수 1개를 출력한다. 모든 학생이 융합인재관으로 건너갈 수 있다면 모든 학생이 건너가기 위한 시행의 최소 횟수를
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
int t = read();
while (t-- > 0) {
int n = read(), m = read(), k = read();
if (m == 1 && k == 1 && n > 1) {
sb.append("-1\n");
continue;
}
int cnt = -1;
do {
n -= m * k;
cnt += 2;
} while (n++ > 0);
sb.append(cnt).append("\n");
}
bw.write(sb.toString());
bw.flush();
}
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' 카테고리의 다른 글
[백준] 4811 알약 - Dynamic Programming / Java (0) | 2024.01.17 |
---|---|
[백준] 25632 소수 부르기 게임 - Greedy / Java (0) | 2024.01.16 |
[백준] 25287 순열 정렬 - Greedy / Java (0) | 2024.01.14 |
[백준] 2864 5와 6의 차이 - Greedy / Java (0) | 2024.01.13 |
[백준] 10263 Opening Ceremony - Greedy / Java (0) | 2024.01.12 |
댓글