zoukankan      html  css  js  c++  java
  • Gym101128G:Game of Cards

    题意:

    有P摞纸牌和一个数字k,每次可以从一摞中拿0-k张牌,拿完再剩下的牌中的第一张数字是几,就必须再拿几张,谁不能拿谁输。

    emmm感觉好像就是裸的SG游戏啊,数据不大,递推出每一摞牌的SG值,然后不同摞之间直接异或一下,如果最后结果是0那么先手必输否则先手必胜。

    刚好那几天一直在学SG,所以在场上很容易A掉了,得瑟了好久~

     1 #include <cstdio>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <iostream>
     5 
     6 using namespace std;
     7 const int maxn=1000+10;
     8 int p,k;
     9 int a[maxn];
    10 int SG[maxn],vis[maxn];
    11 void get_SG(int n){
    12     memset(SG,0,sizeof(SG));
    13     for(int i=1;i<=n;i++){
    14         memset(vis,0,sizeof(vis));
    15         for(int j=0;j<=min(i,k);j++){
    16             if(j==i)continue;
    17             int tmp=i-j-a[i-j];
    18             if(tmp>=0)
    19                 vis[SG[tmp]]=1;
    20         }
    21         for(int j=0;;j++){
    22             if(!vis[j]){
    23                 SG[i]=j;
    24                 break;
    25             }
    26         }
    27     }
    28     return ;
    29 }
    30 int main(){
    31     scanf("%d%d",&p,&k);
    32     int ans=0;
    33     for(int i=1;i<=p;i++){
    34         scanf("%d",&a[0]);
    35         for(int j=1;j<=a[0];j++)
    36             scanf("%d",&a[j]);
    37         get_SG(a[0]);
    38         ans^=SG[a[0]];
    39     }
    40     if(ans)
    41         printf("Alice can win.");
    42     else
    43         printf("Bob will win.");
    44 
    45 return 0;
    46 }
    View Code
  • 相关阅读:
    Mongodb副本集集群搭建
    Mongodb分片副本集集群搭建
    python-字符串格式化
    python -序列化
    python-装饰器
    Python-内置函数
    CPU性能测试
    python-生成随机字符
    python-布尔值
    python学习-day3
  • 原文地址:https://www.cnblogs.com/LQLlulu/p/8776620.html
Copyright © 2011-2022 走看看