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 }
  • 相关阅读:
    94. Binary Tree Inorder Traversal
    101. Symmetric Tree
    38. Count and Say
    28. Implement strStr()
    实训团队心得(1)
    探索性测试入门
    LC.278. First Bad Version
    Search in Unknown Sized Sorted Array
    LC.88. Merge Sorted Array
    LC.283.Move Zeroes
  • 原文地址:https://www.cnblogs.com/jian1573/p/3053169.html
Copyright © 2011-2022 走看看