-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path반전 요세푸스.cc
45 lines (36 loc) · 908 Bytes
/
반전 요세푸스.cc
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <deque>
using namespace std;
int main() {
int N, K, M;
cin >> N >> K >> M;
deque<int> dq;
for (int i = 0; i < N; i++) {
dq.push_back(i + 1);
}
int cnt = 0;
bool check = true;
while (!dq.empty()) {
if (check) { // 순방향
for (int i = 0; i < K - 1; i++) {
dq.push_back(dq.front());
dq.pop_front();
}
cout << dq.front() << "\n";
dq.pop_front();
}
else { // 역방향
for (int i = 0; i < K - 1; i++) {
dq.push_front(dq.back());
dq.pop_back();
}
cout << dq.back() << '\n';
dq.pop_back();
}
cnt++;
if (cnt == M) {
check = !check;
cnt = 0;
}
}
}