dh-winternagi 님의 블로그
(11866) 요세푸스 문제 0 본문
https://www.acmicpc.net/problem/11866
단계별로 풀어보기
16단계(스택, 큐, 덱 1) 8번째

#include <iostream>
#include <queue>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
vector<int> ans;
queue<int> q;
int n, k;
cin >> n >> k;
for(int i=1;i<=n;i++) q.push(i);
while(!q.empty()){
for(int x=1;x<k;x++){
q.push(q.front());
q.pop();
}
ans.push_back(q.front());
q.pop();
}
cout << "<" << ans[0];
for(int i=1;i<n;i++) cout << ", " << ans[i];
cout << ">";
return 0;
}'백준 (C++) > Solve' 카테고리의 다른 글
| (2346) 풍선 터트리기 (0) | 2026.04.16 |
|---|---|
| (28279) 덱 2 (0) | 2026.04.15 |
| (2164) 카드2 (0) | 2026.04.15 |
| (18258) 큐 2 (0) | 2026.04.15 |
| (12789) 도키도키 간식드리미 (0) | 2026.04.15 |
