zoukankan      html  css  js  c++  java
  • [POJ3630]Phone List (Tire)

    题意

    trie字典树模板

    LOJ有中文翻译https://loj.ac/problem/10049

    思路

    TIRE

    代码

    之前在LOJ上做过

    直接交了

    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    #include<cmath>
    #include<map>
    #include<queue>
    #include<stack>
    #include<cstring>
    #include<string>
    using namespace std;
    #define N 100000+5
    int T,n,tot;
    int ch[N][15];
    bool bo[N];
    char s[15];
    bool insert(char *s)
    {
        int len = strlen(s);
        int u = 1;
        bool fl = false;
        for (int i = 0; i < len; i++)
        {
            int c = s[i] - 48;
            if (!ch[u][c]) {
                ch[u][c] = ++tot;
            }
            else {
                if (i == len-1)
                {
                    fl = true;
                }
            }
            u = ch[u][c];
            if (bo[u]) fl = true;
        }
        bo[u] = true;
        return fl;
    }
    int main()
    {
        scanf("%d", &T);
        while (T--)
        {
            scanf("%d",&n);
            tot = 1;
            memset(ch, 0, sizeof(ch));
            memset(bo, false, sizeof(bo));
            bool ans = false;
            for (int i = 1; i <= n; i++)
            {
                scanf("%s", s);
                if (insert(s)) ans = true;
            }
            if (!ans) puts("YES");
            else puts("NO");
        }
        return 0;
    }
  • 相关阅读:
    du熊学斐波那契I
    《博客园精华集》分类索引
    C++中指针和引用的区别
    堆和栈的区别
    getch和getchar的区别
    class和struct
    ARM开发步骤
    ARM寻址方式
    存储器映射
    思维中的错误
  • 原文地址:https://www.cnblogs.com/lincold/p/10228914.html
Copyright © 2011-2022 走看看