๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“ ์•Œ๊ณ ๋ฆฌ์ฆ˜/BOJ

[C++/BOJ] 2164 : ์นด๋“œ2 (Queue)

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