Recent Posts
Notice
No Rules Rules
요세푸스 문제 (feat. 백준, 1158번) 본문
728x90
반응형
요세푸스 문제
https://www.acmicpc.net/problem/1158
반응형
// woohyeon.kim
// kim519620.tistory.com
#include <iostream>
#include <queue>
using namespace std;
int main(){
ios::sync_with_stdio(false), cin.tie(NULL);
register int N, K;
bool arr[5001]{false};
queue<int> ans;
cin >> N >> K;
for(register int n = 1; n <= N; ++n)
arr[n] = true;
register int pos = 0, index = 0;
while(ans.size() != N){
index = 0;
while(index != K){
if(pos == N)
pos = 0;
if(arr[++pos])
++index;
}
ans.push(pos);
arr[pos] = false;
}
cout << "<" << ans.front(), ans.pop();
while(!ans.empty())
cout << ", " << ans.front(), ans.pop();
cout << ">";
return 0;
}
// *&)*@*
요구사항에 따라 빈자리를 제외하고 K만큼 건너띄며 값을 출력하는 문제입니다.
728x90
반응형
'생활 > 코테' 카테고리의 다른 글
부분수열의 합 (feat. 백준, 1182번) (0) | 2022.09.15 |
---|---|
로또 (feat. 백준, 6603번) (0) | 2022.09.15 |
중복 빼고 정렬하기 (feat. 백준, 10867번) (0) | 2022.09.15 |
보물 (feat. 백준, 1026번) (0) | 2022.09.15 |
새로운 게임 (feat. 백준, 17780번) (0) | 2022.09.15 |
Comments