π μκ³ λ¦¬μ¦/BOJ
[C++/BOJ] 2164 : μΉ΄λ2 (Queue)
xxilliant
2024. 11. 17. 11:44
728x90
λ°μν
https://www.acmicpc.net/problem/2164
λ°±μ€ μ€λ²4
νλ‘ νμ΄μΌ νλ€
λμΉκΈ° μ¬μ΄ 쑰건 -> 1μ μ λ ₯ν λ, 0μ΄ μλ 1μ΄ λμμΌ ν¨. (νμ μ΅μ 1κ°λ λ¨μμΌ νλ€)
λμ νμ΄
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n = 0;
int answer = 0;
queue<int> q;
cin >> n;
for (int i = 1; i <= n; ++i)
{
q.push(i);
}
while(1)
{
if(q.size()<=1){
answer = q.front();
break;
}
q.pop();
int t = q.front();
q.pop();
q.push(t);
}
cout << answer;
return 0;
}
728x90
λ°μν