• 문제 링크
https://www.acmicpc.net/problem/27042
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayDeque;
import java.util.Queue;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
Queue<Integer> q = new ArrayDeque<>();
int n = read();
for (int i = 1; i <= n; i++) q.offer(i);
while (q.size() != 1) {
q.offer(q.poll());
q.poll();
}
bw.write(String.valueOf(q.poll()));
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' 카테고리의 다른 글
[백준] 30891 볶음밥 지키기 - Brute Force / Java (0) | 2025.01.05 |
---|---|
[백준] 30611 Course Prerequisites - Data Structure / Java (0) | 2025.01.04 |
[백준] 11344 Waiting for Change - Data Structure / Java (0) | 2025.01.02 |
[백준] 29779 Colliding Encoding - Data Structure / Java (0) | 2025.01.01 |
[백준] 26496 Palins - Data Structure / Java (0) | 2024.12.31 |
댓글