HDU 1536 && POJ 2960 S-Nim SG函数

一开始没用记忆化搜索啊!T到没朋友啊!

后来用了记忆化搜索啊!还是T到没朋友啊!

再后来看了网上的标程啊!尼玛居然连sort都没sort就能过啊!

我当这能省时间啊!结果我特么就WA了啊!WA到没朋友啊!

结果网上那程序还是特么能过啊!我真的脸黑么啊啊啊啊啊!!!!

好了总结一下:

1、还是要sort的,也要用记忆化搜索。

2、这题居然卡我的memset的次数?!总算知道没朋友的原因了。

3、SG函数的应用。

标程满天飞的年代,我只是纪念下而已。

//HDU-1536.cpp
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <cctype>
#include <algorithm>
#include <iostream>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <utility>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
//const double pai = acos(-1.0);
const double pai = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
typedef long long love_live;

int oparr[117], sg[10017], kk;

int getsg(int x){
    if(sg[x] != -1){
        return sg[x];
    }
    int mex[117] = {0}, i, j, k;
    for(i = 0; i < kk; i++){
        int tmp = x - oparr[i];
        if(tmp < 0){
            break;
        }
        getsg(tmp);
        mex[sg[tmp]] = 1;
    }
    int ans = 0;
    for(i = 0; i <= 100; ++i){
        if(!mex[i]){
            ans = i;
            break;
        }
    }
    return sg[x] = ans;
}

int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
   // freopen("output", "w", stdout);
    freopen("input", "r", stdin);
#endif
    int n, m, i, j, k, l, ans;
    while(scanf("%d", &kk) != EOF){
        if(kk == 0){
            break;
        }
        memset(oparr, 0, sizeof(oparr));
        for(i = 0; i < kk; ++i){
            scanf("%d", &oparr[i]);
        }
        sort(oparr, oparr + kk);
        scanf("%d", &m);
        memset(sg, -1, sizeof(sg));
        sg[0] = 0;
        while(m--){
            scanf("%d", &l);
            ans = 0;
            for(i = 0; i < l; ++i){
                scanf("%d", &k);
                ans ^= getsg(k);
            }
            if(ans != 0){
                printf("W");
            }
            else{
                printf("L");
            }
        }
        printf("\n");
    }
return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值