zoukankan      html  css  js  c++  java
  • hdu 1671 Phone List

    这题的题解随处可见。仅供参考。

    ac代码:

    View Code
    #include <algorithm>
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <cstdio>
    #include <string>
    #include <set>
    
    using namespace std;
    
    const int maxn=10;
    const int maxlen=11;
    
    typedef struct TrieNode
    {
        int flg;
        struct TrieNode *next[maxn];
    }TrieNode;
    
    TrieNode memory[1000000];
    int allop=0,nflg=0;
    
    void InitTrieRoot(TrieNode **pRoot)
    {
        *pRoot=NULL;
    }
    
    TrieNode *CreatTrieNode()
    {
        TrieNode *p;
        p=&memory[allop++];
        p->flg=0;
        for(int i=0;i<maxn;i++)
            p->next[i]=NULL;
        return p;
    }
    
    void InsertTrieNode(TrieNode **pRoot,char *s)
    {
        TrieNode *p;
        if(!(p=*pRoot))
            p=*pRoot=CreatTrieNode();
        int i=0;
        while(s[i])
        {
            int k=s[i++]-'0';
            if(p->next[k])
            {
                if(p->next[k]->flg==1||s[i]=='\0')
                {
                    nflg=1;
                    return;
                }
            }
            else
                p->next[k]=CreatTrieNode();
            p=p->next[k];
        }
        p->flg=1;
    }
    int main()
    {
        TrieNode *root;
        int ncas,n;
        char ss[maxlen];
        scanf("%d",&ncas);
        while(ncas--)
        {
            nflg=allop=0;
            InitTrieRoot(&root);
            scanf("%d",&n);
            getchar();
            for(int tt=1;tt<=n;tt++)
            {
                gets(ss);
                if(!nflg)
                    InsertTrieNode(&root,ss);
            }
            nflg?printf("NO\n"):printf("YES\n");
        }
        return 0;
    }

    只是这题不晓得为什么用我常用的那个字典树的模板就过不掉。郁闷。

    勸君惜取少年時&莫待無花空折枝
  • 相关阅读:
    Spark2.x学习笔记:Spark SQL程序设计
    Spark2.x学习笔记:Spark SQL的SQL
    Spark2.x学习笔记:Spark SQL快速入门
    Hystrix入门执行过程
    redis配置master-slave模式
    MockServer 入门
    Locust分布式负载测试工具入门
    poi读取excel元素
    hadoop+spark集群搭建入门
    Vi文档
  • 原文地址:https://www.cnblogs.com/RainingDays/p/2766569.html
Copyright © 2011-2022 走看看