* Computer Science/Algorithm

baekjun 조세푸스 수열

soicem 2018. 8. 27. 15:41

 j(n, v)에서 v가 원을 따라 움직이면 시작점도 따라 움직임


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
30
31
#include <iostream>
#include <list>
 
using namespace std;
 
void josep(list<int> queueint loc) {
    while (!queue.empty()) {
        for (int i = 1; i < loc; i++) {
            queue.push_back(queue.front());
            queue.pop_front();
        }
        if (queue.size() == 1)
            cout << queue.front() << ">";
        else
            cout << queue.front() << ", ";
        queue.pop_front();
    }
}
 
int main() {
    int n, v;
    cin >> n >> v;
    list<int> queue;
    for (int i = 1; i <= n; i++)
        queue.push_back(i);
        
    cout << "<";
    josep(queue, v);
    //system("pause");
    return 0;
}
cs


'* Computer Science > Algorithm' 카테고리의 다른 글

baekjun 7569. 토마토2  (0) 2018.10.05
baekjun 7576. 토마토  (0) 2018.10.05
baekjun 1966. printerQueue  (0) 2018.08.24
baekjun 9012. 괄호  (0) 2018.08.22
baekjun 1874. 스택 순열  (0) 2018.08.22