dh-winternagi 님의 블로그
(2346) 풍선 터트리기 본문
https://www.acmicpc.net/problem/2346
단계별로 풀어보기
16단계(스택, 큐, 덱 1) 10번째

#include <iostream>
#include <queue>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<int> v(n+1);
deque<int> dq;
for(int i=1;i<=n;i++){
cin >> v[i];
dq.push_back(i);
}
int now= 1;
dq.pop_front();
cout << "1 ";
while(!dq.empty()){
if(v[now]>0){
for(int i=1;i<v[now];i++){
dq.push_back(dq.front());
dq.pop_front();
}
now= dq.front();
dq.pop_front();
cout << now << " ";
}else{
for(int i=1;i<-v[now];i++){
dq.push_front(dq.back());
dq.pop_back();
}
now= dq.back();
dq.pop_back();
cout << now << " ";
}
}
return 0;
}'백준 (C++) > Solve' 카테고리의 다른 글
| (15439) 베라의 패션 (0) | 2026.04.16 |
|---|---|
| (24511) queuestack (0) | 2026.04.16 |
| (28279) 덱 2 (0) | 2026.04.15 |
| (11866) 요세푸스 문제 0 (0) | 2026.04.15 |
| (2164) 카드2 (0) | 2026.04.15 |
