zoukankan      html  css  js  c++  java
  • Immediate Decodability HDU1305

    类似phonelist  一次ac

    判断失败主要有两个要点

    1. 是否包含了某段的结尾结点   说明某段被此段包含

    2.此段的结尾结点是否为某段的痕迹   说明此段被包含

    #include<bits/stdc++.h>
    using namespace std;
    int trie[400100][10];
    int sum[400100];
    int pos=0;
    
    bool insert1( char *word )
    {
        int root=0;
        for(int i=0;i<strlen(word);i++)
        {   int ch=word[i]-'0';
            if(trie[root][ ch ]==0)
                trie[root][ ch ]=++pos;
            if(sum[root]==2&&root!=0)return false;
              sum[root]=1;
            root=trie[root][ch];
    
    
        }
          if(sum[root]!=1)  sum[root]=2;
          else  return false;
      return true;
    }
    
    int main()
    {
        char word[10];int cas=0;
        while(gets(word))
        {   int ok=1;
    
    
            memset(sum,0,sizeof(sum));
            memset(trie,0,sizeof(trie));
    
              if(!insert1(word)){ok=0;}
            while(gets(word)&&word[0]!='9')
            {   if(ok==0)continue;
                if(!insert1(word)){ok=0;}
    
    
            }
    
           if(ok)printf("Set %d is immediately decodable
    ",++cas);
            else printf("Set %d is not immediately decodable
    ",++cas);
    
    
        }
    }
    View Code
  • 相关阅读:
    Docker Private Registry
    Dockerfile
    docker存储卷
    392. 判断子序列
    1576. 替换所有的问号
    270. 最接近的二叉搜索树值
    292. Nim 游戏
    680. 验证回文字符串 Ⅱ
    876. 链表的中间结点
    543. 二叉树的直径
  • 原文地址:https://www.cnblogs.com/bxd123/p/10344273.html
Copyright © 2011-2022 走看看