zoukankan      html  css  js  c++  java
  • hdu 2999Stone Game, Why are you always there?

     链接:http://acm.hdu.edu.cn/showproblem.php?pid=2999

    题意:先给定可操作数的集合(有重复),每次操作必须拿集合中到数且是连续的, 不能操作为负; 然后有M次询问, 每次总数为k的石头;

    思路: 通过求sg函数,枚举下一个状态,sg=0则为必败点, 数据量有点大, 要注意姿势,不然会 T;

    View Code
     1 #include <cstring>
     2 #include <cstdio>
     3 #include <algorithm>
     4 using namespace std;
     5 int N, M, L, k;
     6 int a[1005];
     7 int sg[1005];
     8 int mex(int x)
     9 {
    10     if(sg[x]!=-1)return sg[x];
    11     bool re[1005]={0};
    12     for( int i=0; i<L&& a[i]<=x; ++ i ){
    13         for( int j=0; j+a[i]<=x; ++ j ){
    14             re[mex(j)^mex(x-j-a[i])]=1;
    15         }
    16     }
    17     int i=0;
    18     while( re[i] )i++;
    19     return sg[x]=i;
    20 }
    21 int main()
    22 {
    23     while( scanf("%d", &N)==1 ){
    24         for(int i=0; i<N; ++ i){
    25             scanf("%d", &a[i]);
    26         }
    27         sort(a, a+N);
    28         L=1;
    29         for( int i=1; i<N; ++ i ){
    30             if( a[i]!=a[i-1] )
    31                 a[L++]=a[i];
    32         }
    33         scanf("%d", &M);
    34         memset(sg, -1, sizeof(sg));
    35         for( int i=0; i<M; ++ i ){
    36             scanf( "%d", &k );
    37             if(mex(k))puts("1");
    38             else puts("2");
    39         }
    40     }
    41     return 0;
    42 }
  • 相关阅读:
    团队作业六
    团队作业五
    团队作业(四)
    团队作业(三)
    团队作业二
    宇宙圣斗士队介绍
    团队作业之七
    团队作业之六
    团队作业五
    奥特曼小分队之四(Work Breakdown Structure)
  • 原文地址:https://www.cnblogs.com/jian1573/p/3053169.html
Copyright © 2011-2022 走看看