https://www.acmicpc.net/problem/2164
아이디어:
1. 큐에 1부터 n까지 push()
2. 큐 크기가 1이 될 때까지 pop(), push(), pop()
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
queue<int> Q;
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;
}
'algorithm' 카테고리의 다른 글
백준 10866번 덱 (0) | 2025.03.30 |
---|---|
덱 (0) | 2025.03.30 |
백준 10845번 큐 (0) | 2025.03.29 |
큐 (0) | 2025.03.29 |
백준 6549번 히스토그램에서 가장 큰 직사각형 (0) | 2025.03.29 |