Notice
Recent Posts
Recent Comments
Link
«   2026/06   »
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
Archives
Today
Total
관리 메뉴

dh-winternagi 님의 블로그

(2164) 카드2 본문

백준 (C++)/Solve

(2164) 카드2

dh-winternagi 2026. 4. 15. 09:35

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

단계별로 풀어보기

16단계(스택, 큐, 덱 1) 7번째

 

 

 

제일 위 카드를 아래로 옮기는 과정은 큐에서 제일 앞 원소를 다시 넣은 뒤 빼는 것과 같다.

 

 

 

#include <iostream>
#include <queue>
using namespace std;

int main() 
{
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  
  queue<int> q;
  int n;
  
  cin >> n;
  
  for(int i=1;i<=n;i++)  q.push(i);
  
  while(q.size()>1){
    q.pop();
    
    q.push(q.front());
    q.pop();
  }
  
  cout << q.front();
  
  return 0;
}

'백준 (C++) > Solve' 카테고리의 다른 글

(28279) 덱 2  (0) 2026.04.15
(11866) 요세푸스 문제 0  (0) 2026.04.15
(18258) 큐 2  (0) 2026.04.15
(12789) 도키도키 간식드리미  (0) 2026.04.15
(4949) 균형잡힌 세상  (0) 2026.04.15