티스토리 뷰

PS/boj

boj)2164 - 카드2

kingsubin 2020. 10. 12. 16:28
import java.io.*;
import java.util.*;

public class boj_2164 {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws IOException {
        Queue<Integer> q = new LinkedList<Integer>();

        int N = Integer.parseInt(br.readLine());
        for (int i = 1; i <= N; i++) {
            q.offer(i);
        }

        while (q.size() != 1) {
            q.poll();
            q.offer(q.poll());
        }

        System.out.println(q.poll());
    }
}

 

- 큐 자료구조 사용해서 풀이

'PS > boj' 카테고리의 다른 글

boj)4949 - 균형잡힌 세상  (0) 2020.10.13
boj)6198 - 옥상 정원 꾸미기  (0) 2020.10.13
boj)2493 - 탑  (0) 2020.10.12
boj)10773 - 제로  (0) 2020.10.12
boj)1748 - 수 이어쓰기 1  (0) 2020.09.22