https://www.acmicpc.net/problem/27724
27724번: 팝핀 소다
입력의 첫 번째 줄에 대회에 참가하는 선수의 수 $N$, 일어날 수 있는 이변의 수 $M$, 시은이의 탄산 내성 $K$가 공백으로 구분되어 주어진다. 주어지는 모든 수는 정수이다. $(2 \le N \le 262\,144;$ $0 \le
www.acmicpc.net
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
public static void main(String[] args) throws Exception {
st = new StringTokenizer(br.readLine(), " ");
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(st.nextToken());
int n = 0;
while (1 < N) {
N /= 2;
n++;
}
int a = 1;
int cnt = 0;
while (a < K) {
a *= 2;
cnt++;
}
if (a != K) cnt--;
int result = cnt + M;
System.out.print(n < result ? n : result);
}
}
'OJ' 카테고리의 다른 글
[BOJ] 1780 종이의 개수 (JAVA) (0) | 2023.04.21 |
---|---|
[BOJ] 19699 소-난다! (JAVA) (0) | 2023.04.20 |
[BOJ] 27737 버섯 농장 (JAVA) (0) | 2023.04.18 |
[BOJ] 27868 On My Way Dorm (JAVA) (0) | 2023.04.17 |
[BOJ] 27736 찬반투표 (JAVA) (0) | 2023.04.16 |