28066 - 타노스는 요세푸스가 밉다
2025. 2. 25. 19:06ㆍPS/백준
문제
https://www.acmicpc.net/problem/28066
느낀점
구현 기본 문제, 왜 이렇게 헤맸지.. 시간 복잡도에 걸릴까봐 이상하게 풀다가 간단하게 데크로 풀었다..
풀이
#include <deque>
#include <iostream>
using namespace std;
int main()
{
int N, K;
cin >> N >> K;
deque<int> arr(N);
for (int i = 0; i < N; i++)
{
arr[i] = i + 1;
}
int base = 0;
int cnt = 0;
while (true)
{
if (N - cnt < K)
{
break;
}
int temp = arr.front();
for (int i = 0; i < K; i++)
{
arr.pop_front();
cnt++;
}
cnt--;
arr.push_back(temp);
}
cout << arr[0];
return 0;
}
'PS > 백준' 카테고리의 다른 글
1421 - 나무꾼 이다솜 (0) | 2025.02.26 |
---|---|
1283 - 단축키 지정 (0) | 2025.02.26 |
6137 - 문자열 생성 (0) | 2025.02.25 |
3151 - 합이 0 (0) | 2025.02.25 |
24523 - 내 뒤에 나와 다른 수 (0) | 2025.02.24 |