zoukankan      html  css  js  c++  java
  • hdu 1847 Good Luck in CET-4 Everybody! (SG函数入门)

     1 /*******************************************************
     2 题目:     Good Luck in CET-4 Everybody!(hdu 1847)
     3 链接:     http://acm.hdu.edu.cn/showproblem.php?pid=1847
     4 算法:     博弈(SG函数)
     5 算法思想: SG(x)=mex{SG(y)|y是x的后继},y就是x能通过一步
     6            变换得到的。mex就是SG(y)中没有出现的最小的非
     7            负整数。最后只要判断SG(x)是否为零。
     8 ********************************************************/
     9 #include<cstdio>
    10 #include<cstring>
    11 #include<algorithm>
    12 #include<iostream>
    13 using namespace std;
    14 
    15 const int mx=1005;
    16 int a[20];
    17 int sg[mx];
    18 int vs[mx];
    19 
    20 void getsg()
    21 {
    22     for (int i=1;i<=1000;i++)
    23     {
    24         memset(vs,0,sizeof(vs));
    25         for (int j=0;j<10&&i>=a[j];j++) vs[sg[i-a[j]]]=1; ///i-a[j]为i的后继
    26         for (int j=0;;j++)
    27         {
    28             if (!vs[j])  ///mex中最小没有出现的数
    29             {
    30                 sg[i]=j;
    31                 break;
    32             }
    33         }
    34     }
    35 }
    36 
    37 int main()
    38 {
    39     for (int i=0;i<10;i++) a[i]=(1<<i);
    40     getsg();
    41     int n;
    42     while (~scanf("%d",&n))
    43     {
    44         if (sg[n]) printf("Kiki
    ");
    45         else printf("Cici
    ");
    46     }
    47 }
  • 相关阅读:
    MYSQL判断某个表是否已经存在
    百度、雅虎、谷歌搜索引擎接口调用注意事项
    Codeigniter整合Tank Auth权限类库的教程
    短链接的生成算法
    自定义String
    运算符和结合性
    字符串类封装
    运算符重载
    数组类封装
    友元
  • 原文地址:https://www.cnblogs.com/pblr/p/5710319.html
Copyright © 2011-2022 走看看