一本通1669S-Nim

1669:S-Nim

【输入样例】

2 2 5
3
2 5 12
3 2 4 7
4 2 3 7 12
5 1 2 3 4 5
3
2 5 12
3 2 4 7
4 2 3 7 12
0

【输出样例】

LWW
WWL

【提示】

数据范围与提示:

对于全部数据,0<n,m,k100,0<si,ai104 。

sol:模板,不解释

#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
    ll s=0;
    bool f=0;
    char ch=' ';
    while(!isdigit(ch))
    {
        f|=(ch=='-'); ch=getchar();
    }
    while(isdigit(ch))
    {
        s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
    }
    return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
    if(x<0)
    {
        putchar('-'); x=-x;
    }
    if(x<10)
    {
        putchar(x+'0'); return;
    }
    write(x/10);
    putchar((x%10)+'0');
    return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('
')
const int N=105,B=10005;
int k,S[N],m,n,a[N];
int SG[B],Mark[B];
int main()
{
    int i,j;
    while(true)
    {
        R(k);
        if(!k) break;
        for(i=1;i<=k;i++) R(S[i]);
        sort(S+1,S+k+1);
        SG[0]=0;
        for(i=1;i<=10000;i++)
        {
            for(j=1;S[j]<=i&&j<=k;j++)
            {
                Mark[SG[i-S[j]]]=i;
            }
            for(j=0;;j++) if(Mark[j]!=i)
            {
                SG[i]=j; break;
            }
        }
        R(m);
        while(m--)
        {
            R(n);
            int ans=0;
            for(i=1;i<=n;i++) ans^=SG[read()];
            if(ans) putchar('W');
            else putchar('L');
        }
        putchar('
');
    }
    return 0;
}
/*
input
2 2 5
3
2 5 12
3 2 4 7
4 2 3 7 12
5 1 2 3 4 5
3
2 5 12
3 2 4 7
4 2 3 7 12
0
output
LWW
WWL
*/
View Code
原文地址:https://www.cnblogs.com/gaojunonly1/p/10554827.html