/
oop_nust_misis
/
josephus_problem-forthang
Обзор
Документация
Войти
/
oop_nust_misis
/
josephus_problem-forthang
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
patch
src/library.cpp
18 строк
420 B
forthang
upd library.cpp
23 мар 2025, 23:21
23 мар 2025, 23:21
81b9e9c
Код
Авторство
О чём код?
#include <vector> #include <deque> int josephus_problem(const std::vector<int>& nums, int K) { if (nums.empty()) { return -1; } std::deque<int> circle(nums.begin(), nums.end()); int current_pos = 0; while (circle.size() > 1) { current_pos = (current_pos + K - 1) % circle.size(); circle.erase(circle.begin() + current_pos); } return circle.front(); }