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

    传送门

    字典树

    几乎就是模板

    但是要注意如果每组数据都用一波memset...

    会TLE

    所以要考虑动态删点

    如果要用到再把这个点的数据清空

    没有什么好说的了...

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    char s[5000007];
    int ch[5000007][2],cnt;
    bool pd[5000007],p[5000007];
    int main()
    {
        int t=0;
        while(scanf("%s",s+1)!=EOF)
        {
            int flag=0;
            t++; cnt=0;
            ch[0][0]=ch[0][1]=0;
            while(s[1]!='9')
            {
                int u=0,l=strlen(s+1);
                for(int i=1;i<=l;i++)
                {
                    if(flag) break;
                    int v=s[i]-'0';
                    if(!ch[u][v])
                    {
                        ch[u][v]=++cnt;
                        ch[cnt][0]=ch[cnt][1]=0;
                        pd[cnt]=p[cnt]=0;
                    }
                    u=ch[u][v];
                    if(pd[u]) flag=1;
                    if(i==l)
                    {
                        if(p[u]) flag=1;
                        pd[u]=1;
                    }
                    p[u]=1;
                }
                scanf("%s",s+1);
            }
            if(!flag)
                printf("Set %d is immediately decodable
    ",t);
            else
                printf("Set %d is not immediately decodable
    ",t);
        }
        return 0;
    }
  • 相关阅读:
    单例模式
    Java多线程小例子(三个窗口卖火车票)
    HashMap和HashTable的区别
    javascript操作对象的方法
    javascript基本语法
    其他标签
    头标签
    label标签
    表单标签
    IO流-LineNumberReader
  • 原文地址:https://www.cnblogs.com/LLTYYC/p/9650790.html
Copyright © 2011-2022 走看看