zoukankan      html  css  js  c++  java
  • UPCOJ9526(SG函数打表,nim游戏异或规则)

    #include<bits/stdc++.h>
    using namespace std;
    int f[1007],SG[1007],S[1007];//f为可以选取的石头个数,SG为sg函数,S为后继状态的集合
    int n,l,r;       
    int cnt=0;
    void getSG(int n){//SG函数打表
          int i,j;
          memset(SG,0,sizeof(SG));
          for(i = 1; i <= n; i++){
             memset(S,0,sizeof(S));
             for(j = 0; f[j] <= i && j < cnt; j++)
                 S[SG[i-f[j]]] = 1;
             for(j = 0;;j++) if(!S[j]){
                 SG[i] = j;
                 //printf("%d ",SG[i]);
                 break;
             }
         }
     }
    int nim(int x){
        if(x<l)
            return 0;//无用,都拿不了
        if(l==1)//打表得到的坑点
            return x%(r+l);
        else{//其余可总结出规律
            x-=r;
            x%=(l+r);
            x/=l;
            if(!x)
                return 1;
            else if(x==1)
                return 0;
            else
                return x;
        }
    }
    int main(){
        int t;
        scanf("%d",&t);
        while(t--){
            scanf("%d%d%d",&n,&l,&r);
            //for(int k=l;k<=r;k++)
                //f[cnt++]=k;//将可选取的f数组构建
            int y;
            int ans=0;
            int flag=0;
            //getSG(1000);
            for(int i=1;i<=n;i++){
                scanf("%d",&y);
                if(y>=l&&y<=r)
                    flag=1;
                ans^=nim(y);//nim游戏规律
            }
            puts(ans||flag?"Yes":"No");
        }
        return 0;
    }
    保持热爱 不懈努力 不试试看怎么知道会失败呢(划掉) 世上无难事 只要肯放弃(划掉)
  • 相关阅读:
    Java: Regular Expressions
    Java: Checked & Unchecked Exceptions
    二叉树的构建和层级打印
    [leetcode] 1032: Stream of Characters: Tries&AC自动机
    [leetcode] 1503: Previous Permutation With One Swap
    robot moving on the surface of a square
    killing rabbits
    Find the longest route with the smallest starting point
    [leetcode] Minimum Number of K Consecutive Bit Flips
    检测设备横屏 || 竖屏的状态
  • 原文地址:https://www.cnblogs.com/ldudxy/p/9880562.html
Copyright © 2011-2022 走看看