zoukankan      html  css  js  c++  java
  • 一本通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
  • 相关阅读:
    Livepool
    Eclipse最新版注释模板设置详解
    hashcode详解
    开发集成工具MyEclipse中Outline的问题
    第三章 数据链路层(二)
    Java常考面试题(四)
    collections集合的总括。
    第三章 数据链路层(一)
    Java常考面试题(三)
    Java常考面试题(二)
  • 原文地址:https://www.cnblogs.com/gaojunonly1/p/10554827.html
Copyright © 2011-2022 走看看