문제

이 문제의 포인트는 간단하다. Queue를 사용해 poll()을 해주고 한번 더 poll()한 값을 받아 offer()해주면 끝난다.

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.*;
 
public class Main{
    public static long [] arr;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int number=sc.nextInt();
        Queue<Integer> queue = new LinkedList<Integer>();
        
        int count=1;
        for(int i=0;i<number;i++)
        {
            queue.offer(count);
            count++;
        }
        for(int i=0;i<number-1;i++)
        {
            queue.poll();
            int temp=queue.poll();
            queue.offer(temp);
        }
        while(!queue.isEmpty())
        {
            System.out.println(queue.poll());
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter

https://www.acmicpc.net/problem/2164

 

2164번: 카드2

N장의 카드가 있다. 각각의 카드는 차례로 1부터 N까지의 번호가 붙어 있으며, 1번 카드가 제일 위에, N번 카드가 제일 아래인 상태로 순서대로 카드가 놓여 있다. 이제 다음과 같은 동작을 카드가 한 장 남을 때까지 반복하게 된다. 우선, 제일 위에 있는 카드를 바닥에 버린다. 그 다음, 제일 위에 있는 카드를 제일 아래에 있는 카드 밑으로 옮긴다. 예를 들어 N=4인 경우를 생각해 보자. 카드는 제일 위에서부터 1234 의 순서로 놓여있다. 1을 버리

www.acmicpc.net

 

 

'알고리즘 > 문제' 카테고리의 다른 글

프린터 큐  (0) 2019.07.19
AC  (0) 2019.07.19
후위 표기식  (0) 2019.07.19
창고 다각형  (0) 2019.07.19
임진왜란  (0) 2019.07.13

+ Recent posts