zoukankan      html  css  js  c++  java
  • hdu 1847 Good Luck in CET4 Everybody! (sg)

    http://acm.hdu.edu.cn/showproblem.php?pid=1847

    toj1180完全一样的题。

    用sg函数写一下。将1000内的sg值打表即可。

    code:

    /*#include<cstdio>
    int main(){
        int n ;
        while(~scanf("%d", &n)){
            if(n%3) printf("Kiki\n") ;
            else    printf("Cici\n") ;
        }
        return 0 ;
    }
    */
    #include<cstdio>
    #include<cstring>
    int sg[1001], a[11] ;
    void init(){
        memset(sg, -1sizeof(sg)) ;
        sg[0] = 0, sg[1] = 1 ;
        a[0] = 1 ;
        for(int i=1; i<10; i++){
            a[i] = a[i-1] * 2 ;
            sg[a[i]] = 1 ;//可以一步胜的点sg为1
        }
    }
    int mex(int n){//sg[n]=mex(sg[m]), m为n后继
        if(sg[n]!=-1)   return sg[n] ;
        for(int i=0; i<10; i++){
            int temp = n - a[i] ;
            if(temp<0)  break ;
            if(sg[temp]==0||sg[temp]==-1&&!mex(temp)){
                //n可以一步到sg为0的点
                sg[n] = 1 ;
                return 1 ;
            }
        }
        sg[n] = 0 ;
        return 0 ;
    }
    int main(){
        int n ;
        init() ;
        mex(1000) ;//求sg值
        while(~scanf("%d", &n)){
            if(sg[n])  printf("Kiki\n") ;
            else        printf("Cici\n") ;
        }} 
  • 相关阅读:
    移动页面HTML5自适应手机屏幕宽度
    “流式”前端构建工具——gulp.js 简介
    HDU2602-Bone Collector
    HDU3535-AreYouBusy
    HDU1712-ACboy needs your help
    HDU3496-Watch The Movie
    HDU1171-Big Event in HDU
    POJ2533-Longest Ordered Subsequence
    HDU2084-数塔
    HDU2023-求平均成绩
  • 原文地址:https://www.cnblogs.com/xiaolongchase/p/2482361.html
Copyright © 2011-2022 走看看