Posts [BOJ 백준] 2164번 카드2 / C++
Post
Cancel

[BOJ 백준] 2164번 카드2 / C++


Contents



문제


문제를 보시려면 링크를 클릭해주세요.


풀이


STL queue를 사용하여 풀었습니다.

[삭제, 삽입, 삭제] 를 반복하다 큐의 크기가 1이 되는 순간, 남은 값이 정답임을 알 수 있습니다.


소스 코드


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
#include <iostream>
#include <queue>

using namespace std;

int main(int argc, char**argv) {

	ios::sync_with_stdio(0);
	cin.tie(0);
		
	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;
}



This post is licensed under CC BY 4.0 by the author.

[WebLogic] 웹로직 UDDI Explorer 비활성화 방법

[BOJ 백준] 10866번 덱 / C++

Comments powered by Disqus.