首页 > 其他 > 详细

[POJ3630]Phone List (Tire)

时间:2019-01-06 14:55:40      阅读:136      评论:0      收藏:0      [点我收藏+]

技术分享图片

题意

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;
}

 

[POJ3630]Phone List (Tire)

原文:https://www.cnblogs.com/lincold/p/10228914.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!