阅读193 返回首页    go 阿里云 go 技术社区[云栖]


hdu 1536 S-Nim sg函数

 最入门的sg,水题

/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int c[102];
int sg[10005];
int k,n;
int get_sg(int now)
{
    if(~sg[now])return sg[now];
    int vis[102],i;
    memset(vis,0,sizeof(vis));
    for(i=0;i<k;i++)
    {
        if(now<c[i])continue;
        vis[get_sg(now-c[i])]=1;
    }
    for(i=0;vis[i]==1;i++);
    return sg[now]=i;
}
int main()
{
    while(~scanf("%d",&k)&&k)
    {
        int i,m;
        for(i=0;i<k;i++)scanf("%d",&c[i]);
        scanf("%d",&m);
        memset(sg,-1,sizeof(sg));
        sg[0]=0;
        int ans=0,t;
        while(m--)
        {
            ans=0;
            scanf("%d",&n);
            for(i=0;i<n;i++)
            {
                scanf("%d",&t);
                ans^=get_sg(t);
            }
            putchar(ans?'W':'L');
        }
        puts("");
    }
}


最后更新:2017-04-03 15:21:46

  上一篇:go 一致性hash算法的好文
  下一篇:go hdu 1850 博弈 入门