hihor 学习日记:hiho一下 第四十六周(SG函数)

http://hihocoder.com/contest/hiho46/problem/1

这个SG函数算是讲的比较易懂了,

AC代码:

#include <bits/stdc++.h>

using namespace std;
#define LL long long
const int Mod = 1e9 + 7;
const int maxn = 2e4 + 5;
const double eps = 0.00000001;
const int INF = 0x3f3f3f3f;


int SG[maxn], S[maxn];

void GetSG(int n) {
    SG[0] = 0;
    for (int i = 1; i <= n; i ++) {
        memset(S, 0, sizeof(S));
        S[0] = 1;
        for (int j = 1; j < i; j ++) {
            S[SG[j]] = 1;
            S[SG[j] ^ SG[i - j]] = 1;
        }
        for (int j = 1; ; j ++)
            if(!S[j]) {
                SG[i] = j;
                break;
            }
    }
}

int main()
{
    GetSG(20000);
    int N;
    cin >> N;
    int ans = 0;
    while(N --) {
        int x;
        cin >> x;
        ans ^= SG[x];
    }
    if(ans) cout << "Alice" << endl;
    else cout << "Bob" << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/henu_jizhideqingwa/article/details/84988320
今日推荐