• 문제 링크
27961번: 고양이는 많을수록 좋다
올바른 행동 순서가 될 수 있는 하나의 예시는 아래와 같으며, $4$번보다 더 작은 행동 횟수로 $6$마리의 고양이를 마도카의 집에 들이는 것은 불가능하다. 초기 상태($0$마리) $\rightarrow$ 생성
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));
long n = read(), cat;
int cnt = 0;
if (n > 0) {
cat = cnt = 1;
while (cat < n) {
cat *= 2;
cnt++;
}
}
bw.write(String.valueOf(cnt));
bw.flush();
}
private static long read() throws IOException {
long c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 4641 Doubles - Brute Force / Java (0) | 2023.08.27 |
---|---|
[백준] 11170 0의 개수 - Brute Force / Java (0) | 2023.08.26 |
[백준] 2930 가위 바위 보 - Greedy / Java (0) | 2023.08.24 |
[백준] 28063 동전 복사 - Greedy / Java (0) | 2023.08.23 |
[백준] 5002 도어맨 - Greedy / Java (0) | 2023.08.22 |
댓글