1 solutions

  • 0
    @ 2026-11-15 13:06:39

    C++ :

    #include <iostream>
    using namespace std;
    
    const int MAXN = 100005;
    int F[MAXN];
    
    int main() {
        int n;
        cin >> n;
        int i = 0, p = 0, c = 0;
        while (c < n - 1) {
            if (F[i] == 0) {
                if (p) {
                    F[i] = 1;
                    c++;
                }
                p=!p;
            }
            i = (i + 1) % n ;
        }
        
        int ans = -1;
        for (i = 0; i < n; i++)
            if (F[i] == 0)
                ans = i;
        cout << ans << endl;
        return 0;
    }
    
    • 1

    Information

    ID
    198
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By