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") ;
        }} 
  • 相关阅读:
    RocketMQ
    Docker的基本使用
    logstash、ELK
    spring cloud杂文总结
    手写一个starter
    @SpringBootApplication你知多少?
    使用ElasticSearch
    ElasticSearch安装
    啥是ElasticSearch???
    socket、端口、进程的关系
  • 原文地址:https://www.cnblogs.com/xiaolongchase/p/2482361.html
Copyright © 2011-2022 走看看