IT民工
加油!

1056一样是判断前缀,唯一的区别就是这里是个10叉树。

 

/*Accepted    2776K    110MS    C++    961B    2012-08-02 14:06:58*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef struct
{
    int next[10];
    int alr, end;
}Trie;

Trie t[110000];
int tp, n;

int insert(char *x, int site)
{
    if(t[site].end)
        return 1;
    if(*x)
    {
        t[site].alr = 1;
        if(!t[site].next[*x - '0'])
            t[site].next[*x - '0'] = tp ++;
        insert(x + 1, t[site].next[*x - '0']);
    }
    else
    {
        t[site].end = 1;
        return t[site].alr;
    }
}

int main()
{
    int T, flag;
    char s[11];
    scanf("%d", &T);
    while(T --)
    {
        tp = 1;
        flag = 0;
        scanf("%d", &n);
        while(n --)
        {
            scanf("%s", s);
            if(!flag && insert(s, 0))
                flag = 1;
        }
        if(flag)
            printf("NO\n");
        else
            printf("YES\n");
        memset(t, 0, sizeof(Trie) * (tp + 1));
    }
    return 0;
}

 

 

 

posted on 2012-08-02 14:12  找回失去的  阅读(165)  评论(0编辑  收藏  举报