zoukankan      html  css  js  c++  java
  • poj3630

    trie

    View Code
    #include <iostream>
    #include 
    <cstdio>
    #include 
    <cstdlib>
    #include 
    <cstring>
    using namespace std;

    #define maxl 15
    #define maxn 10005

    struct Node
    {
        Node 
    *next[10];
        
    bool have;
        
    bool end;
    } trie[maxn 
    * maxl];

    int n;
    char st[maxl];
    int ncount;

    bool ins(Node *proot, char *st)
    {
        
    if (proot->end)
            
    return false;
        
    if (st[0== '\0')
        {
            proot
    ->end = true;
            
    return !proot->have;
        }
        
    if (!proot->next[st[0- '0'])
        {
            proot
    ->next[st[0- '0'= trie + ncount;
            ncount
    ++;
            proot
    ->have = true;
            ins(proot
    ->next[st[0- '0'], st + 1);
            
    return true;
        }
        
    return ins(proot->next[st[0- '0'], st + 1);
    }

    void finish(int a)
    {
        
    int b = n - a - 1;
        
    for (int i = 0; i < b; i++)
            scanf(
    "%s", st);
    }

    bool work()
    {
        ncount 
    = 1;
        memset(trie, 
    0sizeof(trie));
        
    for (int i = 0; i < n; i++)
        {
            scanf(
    "%s", st);
            
    if (!ins(trie, st))
            {
                finish(i);
                
    return false;
            }
        }
        
    return true;
    }

    int main()
    {
        
    //freopen("t.txt", "r", stdin);
        int t;
        scanf(
    "%d"&t);
        
    while (t--)
        {
            scanf(
    "%d"&n);
            
    if (work())
                printf(
    "YES\n");
            
    else
                printf(
    "NO\n");
        }
        
    return 0;
    }
  • 相关阅读:
    从web图片裁剪出发:了解H5中的Blob
    玩一把JS的链式调用
    JavaScript中你所不知道的Object(二)--Function篇
    JavaScript中你所不知道的Object(一)
    从Object和Function说说JS的原型链
    angular之scope.$watch
    CSS3动画效果之animation
    CSS3动画效果之transition
    CSS3弹性盒模型 display:box
    WPF 时间编辑控件的实现(TimeEditer)
  • 原文地址:https://www.cnblogs.com/rainydays/p/2105676.html
Copyright © 2011-2022 走看看