码迷,mamicode.com
首页 > Windows程序 > 详细

AcWing 893. 集合-Nim游戏

时间:2019-11-23 18:28:41      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:stream   put   ring   ems   ret   nbsp   ++   class   memset   

//只能拿某些特定个数的石子
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_set>
using namespace std;
const int N = 110, M = 10010;
int n, m;
int s[N], f[M];
int sg(int x) {
    if (f[x] != -1) return f[x];
    unordered_set<int> S;
    for (int i = 0; i < m; i ++ ) {
        int sum = s[i];
        if (x >= sum) S.insert(sg(x - sum));
    }
    for (int i = 0; ; i ++ )
        if (!S.count(i))
            return f[x] = i;
}
int main() {
    cin >> m;
    for (int i = 0; i < m; i ++ ) cin >> s[i];
    cin >> n;
    memset(f, -1, sizeof f);
    int res = 0;
    for (int i = 0; i < n; i ++ ) {
        int x;
        cin >> x;
        res ^= sg(x);
    }
    if (res) puts("Yes");
    else puts("No");
    return 0;
}

 

 

AcWing 893. 集合-Nim游戏

标签:stream   put   ring   ems   ret   nbsp   ++   class   memset   

原文地址:https://www.cnblogs.com/QingyuYYYYY/p/11918945.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!