CMakeLists.txt
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
constexpr size_t MAX_N = 305;
|
||||
|
||||
|
||||
size_t simulate_monkeys(const size_t monkeys_count, const int m) {
|
||||
bool monkeys[MAX_N] = {false};
|
||||
int died_monkeys_count = 0;
|
||||
for (size_t i = 0, current_num = 0;;
|
||||
i = (i + 1) % monkeys_count,
|
||||
current_num = (current_num + 1) % m) {
|
||||
while (monkeys[i]) { i = (i + 1) % monkeys_count; }
|
||||
if (current_num == m - 1) { monkeys[i] = true, died_monkeys_count++; }
|
||||
if (died_monkeys_count == monkeys_count - 1) { break; }
|
||||
}
|
||||
for (int i = 0; i < monkeys_count; i++) {
|
||||
if (!monkeys[i]) { return i; }
|
||||
}
|
||||
throw logic_error("???");
|
||||
}
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int monkeys_count, m;
|
||||
while (cin >> monkeys_count >> m && m) {
|
||||
cout << simulate_monkeys(monkeys_count, m) + 1 << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user