【題解】Codeforces GYM 100500E – IBM Chill Zone

【題目敘述】http://codeforces.com/gym/100500/attachments

#include <iostream>
#include <set>
using namespace std;
 
int t, n, k, sg[55];
 
int main() {
    cin >> t;
    for (int Case = 1; Case <= t; Case++){
        cin >> n >> k;
        for (int i = 1; i <= n; i++){
            set <int> st;
            for (int j = 1; j+k-1 <= i; j++){
                st.insert(sg[j-1]^sg[i-(j+k-1)]);
            }
            for (int j = 0; j <= n; j++){
                if (!st.count(j)){
                    sg[i] = j;
                    break;
                }
            }
        }
        cout << "Case " << Case << ": ";
        if (!sg[n]) cout << "Losing\n";
        else cout << "Winning\n";
    }
}
分享本文 Share with friends