• 문제 링크
14783번: Eenie Meenie Miney Moe
"Eenie, meenie, miney, moe... catch a heifer by the toe," an exasperated Bessie muttered. She could never get the syllables right when choosing calves for game playing. Today she is trying to see which of N (1 <= N <= 2,300) heifers conveniently numbered 1
www.acmicpc.net
• 풀이 코드
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));
int n = read(), l = read();
Queue<Integer> q = new ArrayDeque<>();
int[] arr = new int[l];
for (int i = 1; i <= n; i++) q.offer(i);
for (int i = 0; i < l; i++) arr[i] = read();
int i = 0;
do {
int seq = arr[i++ % l];
while (seq-- > 1) q.offer(q.poll());
q.poll();
} while (q.size() != 1);
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' 카테고리의 다른 글
[백준] 6474 Palindromes - Data Structure / Java (0) | 2024.03.02 |
---|---|
[백준] 4675 Word Amalgamation - Data Structure / Java (0) | 2024.03.01 |
[백준] 5349 Duplicate SSN - Data Structure / Java (0) | 2024.02.28 |
[백준] 14914 사과와 바나나 나눠주기 - Brute Force / Java (0) | 2024.02.27 |
[백준] 14563 완전수 - Brute Force / Java (0) | 2024.02.26 |
댓글