Click Here to go back to the homepage.

Coconut Splat Solution:


#include <bits/stdc++.h>
using namespace std;

int main(){
    // #ifndef TESTING
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    int n_syllables, n_players;
    cin >> n_syllables >> n_players;

    // {state (0, 1, 2),  player #}
    vector<pair<int, int>> players(n_players);
    for(int i = 1; i <= players.size(); i++){
        players[i-1].second = i;
    }
    int index = 0;

    while(players.size() > 1){
        index = (index + n_syllables - 1) % players.size();
        if(players[index].first == 0){
            players[index].first = 1;
            players.insert(players.begin() + index, {1, players[index].second});
        } else if (players[index].first == 1){
            players[index].first = 2;
            index++;
        } else { //equal to 2, palm out and need to be deleted
            players.erase(players.begin() + index);
        }
    }
    cout << players[0].second;

    return 0;
}